I have sort of wizard in app going through 6 Activities.
so I call:
Main Activity - Call Option 1 - Call Option 2 - Call Option 3 - Call Option 4 - Call Option 5
Now, on Option 5 I perform save of the whole action to database, and at that point I need to go back to Main Activity and destroy Option1,2,3,4 and 5.
Until Option 5 saves to database, I need to be able to go back, do changes, go forth to Option 5 and save it.
IS proper way to do it that I somehow create method that would have:
private void cleanStack(){
Option1.finish();
Option2.finish();
Option3.finish();
Option4.finish();
Option5.finish();
}
And then start (or resume) Main Activity?
Tnx
exit(); or finish(); it exit full application or all activity.
Activity can't be killed but Os can kill the whole application. In this case you can try finish() / finishActivity() / context. finish() to finish the activity. While you finish an activity backpress will not return to the previous activity.
If you just want to reload the activity, for whatever reason, you can use this. recreate(); where this is the Activity. This is never a good practice. Instead you should startActivity() for the same activity and call finish() in the current one.
Using putExtra() method, we can send the data. While using it, we need to call setResult() method in services. We can also store data in a common database and access it on services as well as in Activity.
Use the following to clear the stack :
Intent intent = new Intent ( this , MainActivity.class );
intent.addFlags ( Intent.FLAG_ACTIVITY_CLEAR_TOP );
startActivity ( intent );
In this manner, since in the stack you have : Main Activity -> Call Option 1 -> Call Option 2 -> Call Option 3 -> Call Option 4 -> Call Option 5
If you start the MainActivity using the clear top flag, all activities in the stack on top of the MainActivity will be finished.
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