I don't know why this is so difficult to figure out. I have my main activity that, when launched, checks if this is the first time it's been opened. If it is, then it closes the main activity and opens the setup/introduction activity with FLAG_ACTIVITY_NEW_TASK
. The setup process consists of three activities (A, B, and C). At the end of activity C, how do I get it to clear and the setup task that contains A, B, and C and start the main activity again. I've tried adding FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP
to main activity Intent
but when I press BACK, it returns to activity C of the setup process. How do I get it to clear the task of activities A, B, and C when C finishes and starts the main? Thanks!
I'm building in Android 1.6 (API 4), so some of the Activity
flags may be limited.
flag — FLAG_ACTIVITY_CLEAR_TOP: If the Activity being started is already running in the current task then instead of launching the new instance of that Activity, all the other activities on top of it is destroyed (with call to onDestroy method) and this intent is delivered to the resumed instance of the Activity (now ...
A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.
FLAG_ACTIVITY_CLEAR_TOP will clear activities it it is of the same activity instance. Here in your case all your activities are of different instances so FLAG_ACTIVITY_CLEAR_TOP won't work. To clear your task, create an Activity instance in each of your activity and assign that instance 'this' on your onCreate method of every activity. whenever you want to clear your task jus call that instance.finish(). and start the activity that you want.
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