3

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!

neteinstein
  • 17,529
  • 11
  • 93
  • 123

3 Answers3

6

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()

A. Binzxxxxxx
  • 2,812
  • 1
  • 21
  • 33
2

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

aromero
  • 25,681
  • 6
  • 57
  • 79
0

I've ended up using this https://stackoverflow.com/a/8576529/327011 as I needed to use it from 1.5 > and that flag is only avaliable on higher APIs.

If I hadn't the need to support "low" API levels the answer from @aromero would be my option.

Community
  • 1
  • 1
neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • As this answer is outdated i've accepted @A. Binzxxxxxx as the most up-to-date (but haven't tried his code yet). – neteinstein Jan 30 '14 at 12:07