Stefan Bossbaly
Stefan Bossbaly

Reputation: 6794

Clearing Activity Stack

I am having trouble clearing my app's activity stack. At the start of my app I make the user login and give them a session id. After they login they are able to continue on using the app. However if there session expires I want to redirect them to the login activity and clear the Activity history so they can't have access to the app. I looked at the Android API and the Intent flag FLAG_ACTIVITY_CLEAR_TASK seems to be want I want but it was just included in API level 11 and no phones have the new OS yet. Does anyone have a solution to this problem. Thanks.

Upvotes: 1

Views: 2417

Answers (2)

Stefan Bossbaly
Stefan Bossbaly

Reputation: 6794

I found my answer here. Turns out that I have to broadcast an intent to tell all of the Activities to call the method finish().

Upvotes: 2

LeffelMania
LeffelMania

Reputation: 12875

The documentation for FLAG_ACTIVITY_CLEAR_TOP describes the situation you want if you use it in conjunction with FLAG_ACTIVITY_NEW_TASK

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP

"This launch mode can also be used to good effect in conjunction with FLAG_ACTIVITY_NEW_TASK: if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state. This is especially useful, for example, when launching an activity from the notification manager."

Upvotes: 1

Related Questions