Search code examples
androidandroid-activityback-stack

Android Resume activity from Stack


Hi I have a question, I would like to know which intent flag to use to start an activity that may already exist in the backstack, however it should

  1. Clear all activities on top of it, bringing the current activity to top and
  2. It should resume the previous activity (NOT start a new instance of it).

Would really appreciate some help on this!


Solution

  • You use Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP

    This will clear all activities that are on top of the target activity, and call onNewIntent() on the existing instance of the activity (if it exists). Only if there isn't already an instance, it will create a new one.