Thursday, January 29, 2015

Parent Activity is destroyed when providing Up navigation

If providing Up navigation behavior as Android doc: http://developer.android.com/training/implementing-navigation/ancestral.html, when click the Up button on the navigation bar, the parent activity is destroyed then re-created. It is different behavior as pressing back key.

To avoid destroy parent activity, one solution is setting launch mode <singleTop> for the activity in AndroidManifest.xml:
android:launchMode="singleTop"

The different between Up key and Back key is, when pressing Back key, by default, the currently activity is popup from activity stack and finished, so the previously activity shows up. When pressing Up key, the currently activity is popup from stack too, but the parent activity, which is defined in AndroidManifest.xml and maybe not the previously activity, is created to show. By default the launch mode is <standard> so the existed activity task is destroyed then re-create. To set the launch mode to <singleTop>, Android will launch the existed one instead of create a new task.

No comments:

Post a Comment

Thrift fails on Windows - thrift failed error: The command line is too long.

Meet a thrift compiling failure on my project on Windows 7. Using Maven in IntelliJ so I choiced maven-thrift-pluging for thrift files. For ...