You need the FLAG_ACTIVITY_NEW_TASK on the Intent.
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK
The name is a bit of a misnomer. If a task doesn't exist, it will create one. If the task is already there, the activity joins up with the existing task. A "task" is just a stack of activities.
You may also have to tweak your AndroidManifest.xml, as well as combine that flag with other flags like FLAG_ACTIVITY_CLEAR_TOP.
We have an Activity in Square that can be launched explicitly from another Activity, or it can be launched from an item in Android's notification area. Here is a snippet from our AndroidManifest.xml:
<!--
- Shows ***redacted*** from '***' as well as enqueued items.
- singleTop launch mode ensures we don't get a stack of duplicate
- activities when this is launched repeatedly from Android's notification
- area.
-->
<activity
android:name="com.squareup.ui.MyActivity"
android:launchMode="singleTop"
/>
When we launch MyActivity from another Activity, it's done normally:
startActivity(new Intent(this, MyActivity.class));
But when we launch MyActivity from outside an Activity context, we set some flags:
// FLAG_ACTIVITY_NEW_TASK is required. Without it, Android automatically
// adds that flag and logs a warning on every usage.
// FLAG_ACTIVITY_CLEAR_TOP brings the xxxx activity back to
// the top of the stack if it had launched child activities.
Intent intent = new Intent(context, MyActivity.class);
intent.putExtra(EXTRA_BACK_TEXT_ID, R.string.back);
intent.putExtra(EXTRA_VIA_NOTIFICATION, true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
--
Eric M. Burke
636-542-8753 (Google Voice)