Up Button and how to keep Subtitle count displayed

Hi @Willscott and @JuanRomo,

As double checked, the solution to my issue is listed in the following link. It’s not related to the launch mode.

@JuanRomo For your question, if an Activity’s launch mode is set to be singleTask, since activities with “singleTask” or “singleInstance” launch modes can only be at the root of a task, re-parenting is limited to the “standard” and “singleTop” modes.

By the way, I’ve tested three scenarios as follows. I think launch mode singleTop for the parent activity is a better choice.

  1. Click Back Button in CrimePagerActivity
    The CrimeListFragment’s onDestroyView() will not be called. i.e. its state is preserved.

  2. Click Up Button in CrimePagerActivity with CrimeListActivity in singleTop launch mode.
    The CrimeListFragment’s onDestroyView() will not be called. i.e. its state is preserved.
    Same behavior as the previous one.

  3. Click Up Button in CrimePagerActivity with CrimeListActivity in standard launch mode.
    The CrimeListFragment’s onDestroyView() will be called and the fragment will be reestablished. i.e. its state is lost.

The background details can be found in the following guide link.

Similarly, if you navigate up to an activity on the current stack, the behavior is determined by the parent activity’s launch mode. If the parent activity has launch mode singleTop (or the up intent contains FLAG_ACTIVITY_CLEAR_TOP), the parent is brought to the top of the stack, and its state is preserved. The navigation intent is received by the parent activity’s onNewIntent() method. If the parent activity has launch mode standard (and the up intent does not contain FLAG_ACTIVITY_CLEAR_TOP), the current activity and its parent are both popped off the stack, and a new instance of the parent activity is created to receive the navigation intent.

@cstewart Could you help correct me if I miss something from the guide?

By the way, according to the description in section HOW HIERARCHICAL NAVIGATION WORKS of Chapter 13, it says two points.

  1. When the user navigates up from CrimePagerActivity, an intent with flag Intent.FLAG_ACTIVITY_CLEAR_TOP is created.

  2. FLAG_ACTIVITY_CLEAR_TOP tells Android to look for an existing instance of the activity in the stack, and, if there is one, pop every other activity off the stack so that the activity being started will be top-most (Figure 13.12).

This behavior looks like the launch mode of the parent activity is singleTop.

However, according to the description in section “JUST ONE MORE THING…” of Chapter 13, it says the following point.

  1. An unfortunate side effect of the way hierarchical navigation is implemented in Android is that the activity that you navigate up to will be completely re-created from scratch. This means that any instance variables will be lost, and it also means that any saved instance state will be lost as well. This parent activity is seen as a completely new activity.

This behavior looks like the launch mode of the parent activity is standard.

Could you have a double check?

Thank you very much and I’m very enjoying the fantastic book. :wink:

1 Like