According to Android docs:
http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html
\"When the user leaves a task by pressing the Hom
The docs are right, the only possible problem I can think of that is causing this is the device you are testing on, if it works as expected on the emulator (which is stock Android) it should work on at least 90% of Androids, its the manufactures fault for this I believe not Android.
This is a bug in android's platform:
http://code.google.com/p/android/issues/detail?id=2373
The workaround is, to place this in the onCreate method of your main Activity:
if (!isTaskRoot())
{
final Intent intent = getIntent();
final String intentAction = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN))
{
Log.w(LOG_TAG, "Main Activity is not the root. Finishing Main Activity instead of launching.");
finish();
return;
}
}
as extracted from:
How to prevent multiple instances of an activity when it is launched with different intents
...spent 3 days looking out for this.
I'm just going to explain why it fails, and how to reproduce this bug programmatically so you can incorporate this in your test suite:
When you launch an app through Eclipse or Market App, it launches with intent flags: FLAG_ACTIVITY_NEW_TASK.
When launching through the launcher (home), it uses flags: FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_BROUGHT_TO_FRONT | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, and uses action "MAIN" and category "LAUNCHER".
If you would like to reproduce this in a test case, use these steps:
adb shell am start -f 0x10000000 -n com.testfairy.tests.regression.taskroot/.MainActivity
Then do whatever is needed to get to the other activity. For my purposes, I just placed a button that starts another activity. Then, go back to the launcher (home) with:
adb shell am start -W -c android.intent.category.HOME -a android.intent.action.MAIN
And simulate launching it via the launcher with this:
adb shell am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -f 0x10600000 -n com.testfairy.tests.regression.taskroot/.MainActivity
If you haven't incorporated the isTaskRoot() workaround, this will reproduce the problem. We use this in our automatic testing to make sure this bug never occurs again.
Hope this helps!