1

When I start a new activity in a fragment like this

    Intent launchIntent = new Intent();
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    launchIntent.setClassName(getBaseActivity().getPackageName(), MainActivity.class.getName());
    startActivity(launchIntent);
    getBaseActivity().finish();

a fragment of the old activity which is subscribing the same event I want to to catch in the new activity is called. Do I end the old activity wrong or is the fragment not ended? I unregister in the onDestroy method of every fragment and activity.

@Override
public void onDestroy() {
    OttoBus.getInstance().unregister(this);
    super.onDestroy();
}
Sven Mäurer
  • 715
  • 1
  • 9
  • 19

1 Answers1

1

Looks like you called setRetainInstance(true) in the fragment of your "old" activity, that's why onDestroy() method of that fragment is not called (fragment is not destroyed by the OS, just detached from activity and kept in memory).

I would recommend you either to unregister for events in onPause() and register in onStart() or not to retain fragment in memory.

Alex Dmitriev
  • 3,664
  • 3
  • 29
  • 35