I have an app that I have running a media player and I want to resume the activity from my apps home activity.
I can successfully do this by adding the following flags to the startActivity Call:
myIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
I am worried that this is not an ideal way to do things since it took me a long time to find it. It made me think that no one uses it very much.
Are there any pitfalls to using this method?
I know that this question is quite older and may you have solved your problem and may be travelled to mars and back in those years.But just to make things clear for the people coming here and looking for an explanation:
According to Official Documentation:
A-B-C-D
and You have launched another intent StartingActivity A
withFLAG_ACTIVITY_CLEAR_TOP
at this point what android will be do is Simply Clear All the Activities on the Top ofActivity A
, means now your BackStack Will Look like->A
(yes that's it because you have cleared all the activities on top of it).Third Scenario, We start with the same BackStack
A-B-C-D
and We will launch an Intent StartingActivity D
withFLAG_ACTIVITY_SINGLE_TOP
, now our BackStack will look like->A-B-C-D
(Yes the BackStack remains in the Same Order because our FLAG prohibits the launch Same Activity If it is the Currently on Top of the Stack and Showing on the User screen.Last Scenario, We start with our same BackStack
A-B-C-D
and We will launch an Intent StartingActivity D
but this time with no FLAGS, now our BackStack will look like->A-B-C-D-D
.Just to make sure I understand your question correctly: Say your activity stack is something like A -> B -> C, and now from C you want to clear the stack and get back to A.
If this is what you want, then those intent flags are correct and should work as expected, as per the Android-developer docs.