In my navigation the following sequence of activities can be produced: A,B,C,B,C,B,C, …, D.
D activity contains an overriden method for the Back-button, which sends user to the A activity with Intent.FLAG_ACTIVITY_CLEAR_TOP parameter.
Activity A receives a number of necessary extra parameters and my problem is that when I trigger startActivity in D activity with this CLEAR_TOP flag activity A doesn’t seem to get any previous extra or even launch onResume method.
Does it mean that CLEAR_TOP actually recreates the target activity instead of bringing up the old one ? And, is there any system-natural approach to restore those extra intent parameters in activity A when I launch it from activity D.
P.S. Right now the only choice I see is to manually fillin those previous necessary parameters when constructing intent object in D activity. Is it a way to go ?
Thanks.
When you use
CLEAR_TOPflag,target Activitydoes not recreate,but when you use a new intent to appear Activity A,you can only get this new intent’s extras in Activity A.You can save these extras in file,preferences or global application variables,when you leave Activity A.Or you can declare a static method in Activity A that save these extras in it and you would to invoke it from Activity D,before force to appear Activity A:
Activity A:
Activity D:
Edit:
When Activity A appears again,it’s
onCreate()method invokes again and here you can get intent that request it.Then you can get intent’s flag and compare it with67108864(constant for CLEAR_TOP flag).If it equals to this constant you would to retrieve your data from your storage(file,preferences,…).To create global variables you can see this question.