Archie.bpgc Archie.bpgc - 1 year ago 124
Android Question

Resume the Activity instead of Starting if already exists in back stack

I have an

after a lot of steps, say

.... in some
I change some data related to
and call it using

Intent intent = new Intent(Activity_n.this, Activity_1.class);

To refresh the content. But later I can go all the way back to
where I started, which has old data.

Instead I want the initial
' s
to be called, using the above code. Or appropriate Flag


consider a task consisting of the activities: A, B, C, D. If D calls
startActivity() with an Intent that resolves to the component of
activity B, then C and D will be finished and B receive the given
Intent, resulting in the stack now being: A, B.

That' what the docs say, but not what I am getting.

Answer Source

You can add this two lines and try


Write this in your manifest file inside Activity

     android:screenOrientation="portrait" >

"singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.

You can use SingleTask or SingleInstance

"singleTask" - The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.

"singleInstance" - Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

Refer this link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download