I'm not sure I understand the question. Or rather, the reason for not being able to use FLAG_ACTIVITY_CLEAR_TOP
.
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 example, 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.
If I understand correctly, that's exactly what you want. In particular for,
Activity 1 -> Activity 2 -> Activity 3 -> ... Activity N -> press
button ...
Launching an Intent with Activity2.class
and flags FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP
would go back to the existing instance of Activity2 (instead of creating a new one) and deliver the new intent in onNewIntent()
. You just need to add an extra to this intent, so that this method will know that it's supposed to call ActivityX afterwards.
That is, unless I'm missing something. :)