Search code examples
androidandroid-intentandroid-activity

Finishing multiple activities to resume an old one in stack?


I need to finish multiple activities in stack and resume an old one. For example,

There are four activities in stack Act1, Act2, Act3 and Act4. On some event in Act4, I need to finish Act4, Act3 and Act2 to resume Act1.

I tried using Intet.FLAG_ACTIVITY_CLEAR_TOP but it's recreating the activity which is not my requirement.

Advance thanks for suggestions.


Solution

  • You have used Clear_top, it will clear all the activities and bring act1 to front, but, onNewIntent method will be called of you activity, you can perform any task you want in that, after activity starts again. Or, you can use flag FLAG_ACTIVITY_REORDER_TO_FRONT with your intent, it will do:

    FLAG_ACTIVITY_REORDER_TO_FRONT do this:If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

    FLAG_ACTIVITY_CLEAR_TOP will do: If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

    for more information on flags look http://developer.android.com/reference/android/content/Intent.html