Reputation: 985
I am facing a strange issue
: I received the notification and I tab on that with intent for Activity A.
Blockquote (intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); )
When Activity A is opened it call the below method.
(onPause,onCreate, onStart,onResume (Fragment detached) and than onDestroy)
Why on destroy is called for the old instance of the activity when I have already called CLEAR_TOP.
Can someone help me what can be the cause for this?
How can I check if there is any instance is pending in stack already or how can I clear everything? I can not use singleInstance as on notification tab I am redirecting to different fragment.
Upvotes: 2
Views: 74
Reputation: 95578
If you use only FLAG_ACTIVITY_CLEAR_TOP
then all instances of activities will be cleared, back to and including the instance of the target Activity
, and then a new instance of the target Activity
will be created.
If you want to reuse an existing instance, you need to specify both FLAG_ACTIVITY_CLEAR_TOP
and FLAG_ACTIVITY_SINGLE_TOP
like this:
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP);
This will clear all instances of activities back to (but excluding the target Activity
, and call onNewIntent()
on the target Activity
with the new Intent
.
Upvotes: 3