Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage activity stack?

When my stack is in this situation:

A->B->C

if I start D activity, I want that the activity stack becomes:

A->D

Note that activity C is a dialog.

like image 733
Michele Avatar asked Jun 16 '11 09:06

Michele


2 Answers

here are the steps which will do the needed:

  • from activity C launch the activity A with a boolean fromActivityC bundled with the intent and the flag FLAG_ACTIVITY_CLEAR_TOP set .
  • Now in the on create of the activity A check for this boolean "fromActivityC" first and if present launch the activity D else the normal flow continues.

    // following code can be used to get the boolean in the oncreate
    boolean entrypoint=this.getIntent().getExtras().getBoolean("fromActivityC");
    

A lil workaround but Hope it helps

like image 62
Nitin Avatar answered Oct 03 '22 00:10

Nitin


There is several way to remove a activity from the stack or prevent it to be stacked :

To remove your activity from the stack , simply call finish(), see here.

You can also implement in your manifest the property : android:noHistory="true" which prevent an activity to be stacked.

See this question form more detail : Removing an activity from the history stack

like image 24
grunk Avatar answered Oct 02 '22 23:10

grunk