1

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

Neha Shukla
3,6666 gold badges43 silver badges71 bronze badges
asked Jun 17, 2015 at 7:10

2 Answers 2

1

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).

answered Jun 17, 2015 at 7:26
Sign up to request clarification or add additional context in comments.

Comments

0

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

  1. The user opens activity B from activity A.
  2. While B is being opened, another part of your activity (be it BroadcastReceiver, Service, whatever) sends a new Intent to B to do stuff.
  3. B receives this new Intent and handle it in its onNewIntent() 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.

answered Jun 17, 2015 at 7:35

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.