Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing task and start a new activity

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.

like image 722
Brian Avatar asked Jan 17 '12 06:01

Brian


People also ask

What is true about flag activity new task?

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 ...

What is an activity stack?

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.


1 Answers

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.

like image 103
Arun Avatar answered Sep 26 '22 04:09

Arun