Нужно сделать систему событий, решил использовать LocalBroadcastManager:
public abstract class BaseFragment extends Fragment
{
private static final String USER_LOGIN_ACTION = "user_login_action";
private LocalBroadcastManager localBroadcastManager;
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case USER_LOGIN_ACTION:
User user = Parcels.unwrap(intent.getParcelableExtra("user"));
onUserLogin(user);
break;
}
}
};
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(USER_LOGIN_ACTION);
localBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}
@Override
public void onDestroy() {
localBroadcastManager.unregisterReceiver(broadcastReceiver);
super.onDestroy();
}
public void fireUserLogin(User user) {
Intent intent = new Intent(USER_LOGIN_ACTION);
intent.putExtra("user", Parcels.wrap(user));
localBroadcastManager.sendBroadcast(intent);
}
public void onUserLogin(User user) {
//
}
}
Как вы относитесь к такому?