I have 5 activities (let's say A,B,C,D
and E
).
Activities A to D are for setting some data, so user may be able to go back and forth changing whatever.
Activity E
, on the other hand, is the summary, so the user is no longer allowed to go back.
My idea is to finish all previous activities when user gets to E
Currently my activities A
to D
have no flags attached to them.
Activty E is called like this:
Intent I = new Intent(this, SomeClass.class);
I.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(I);
I have read everywhere that those flags are supposed to achieve what I am trying to do, but they doesn't, when user gets to activity E
and presses Back
button, the application goes back to activity D
.
Any ideas? I am missing something? Is this not the right way to solve this problem?
Thanks for your help
Use the method startActivityForResult in each of the activities A, B, C, D instead of startActivity. And when the user exits out of Activity E, handle the backbutton and set the result code in the intent. now in the onActivityResult method of each A, B, C and D classes handle it , close the activity and pass the result to previous activity.
You can also do it as soon as user finishes Activity D. When users go from D to E, you may use the above method to actually go all the way down to Activity A and then open activity E and finish Activity A.
Both the above cases produce the same result from users perspective and they do not see the intermediate activities A, B, C, D unless you are doing some long jobs in the onStart method of those activities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With