Hi I was studying backstack and launchmode from
Android developers.
but not able to understand the meaning of note . Please explain asap
cant attach image
Note: When a new instance of an Activity is created, the user can press the Back Button to return to the previous Activity. But when an existing instance of an Activity handles a new Intent, the user cannot press the Back Button to return to the state of the Activity before the new Intent arrived in onNewIntent()
under single top
https://developer.android.com/guide/components/tasks-and-back-stack.html
2 Answers 2
Consider an activity at the top of the stack. Since it's in the singleTop mode, it receives an intent via onNewIntent() method.
Now, suppose that the onNewIntent() method loads a new image in an ImageView in the activity. Now, when you press back, the ImageView wont go back to having the previous image. i.e. It won't return to the previous state.
If the stack at this point was A-B-C-D, with D receiving the onNewIntent() call. The image view in D gets updated. Now, pressing back, will take the user to C.
In the standard launch mode, the stack becomes A-B-C-D(1)-(receive new intent)-D(2), and in this case, when you press back from D(2) you're taken back to D(1).
Comments
In an activity labeled as singleTop, any incoming Intent at any given will be handled by the currently existing instance, in contrast to creating a new instance of that activity (like a "normal" activity would).
Suppose your app flows like this (with B labeled as a singleTop activity):
A -> B
- The user opens activity
Bfrom activityA. - While
Bis being opened, another part of your activity (be itBroadcastReceiver,Service, whatever) sends a newIntenttoBto do stuff. Breceives this new Intent and handle it in itsonNewIntent()method.
At this point, when your user taps that back button, B will go back to A, as opposed to return to the state before step 2.
That is what your "note" basically trying to say.