Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset all activities and launch a new one?

Tags:

android

I have an application in which i want to navigate this way:

A -> B -> C

And from C launch a new activity called D, that goes to top and also clears the task, meaning that if i press back on D it goes to home screen.

If i understand it correctly this FLAG: FLAG_ACTIVITY_TASK_ON_HOME does this... but it's only on current APIs (11>).

I'm developing for Android 1.5> how can i also have this behaviour?

Thanks!

like image 663
neteinstein Avatar asked Dec 27 '25 16:12

neteinstein


2 Answers

you are looking for this:

Intent intent = new Intent(activity, activityClass);
ComponentName cn = intent.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
activity.startActivity(mainIntent);

use android compatibillity lib from google - found in the sdk.

or use finish()

like image 69
A. Binzxxxxxx Avatar answered Dec 30 '25 04:12

A. Binzxxxxxx


You can use FLAG_ACTIVITY_CLEAR_TASK along with FLAG_ACTIVITY_NEW_TASK.

public static final int FLAG_ACTIVITY_CLEAR_TASK

Since: API Level 11

If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

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

like image 44
aromero Avatar answered Dec 30 '25 06:12

aromero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!