FLAG_ACTIVITY_NEW_TASK clarification needed

Try this. It works for me.

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

In your 3rd step when you open App2 and start App1.Screen1 with Intent.FLAG_ACTIVITY_NEW_TASK you need to also set Intent.FLAG_ACTIVITY_SINGLE_TOP to get this to do what you want. It's an Android bug :-(

Be also aware that the behaviour is also a bit broken if you launch your app for the first time from your IDE (IntelliJ, Eclipse), or after installing it via the market (Google Play) or from a browser download. See How to prevent multiple instances of an activity when it is launched with different intents and http://code.google.com/p/android/issues/detail?id=26658


Android has TONS of bugs related to activities and tasks.

Nevertheless, Google changed the behavior of tasks between OS versions and didn't notify the developers, which is the most annoying thing about it.

jakk - If you didn't set any flags on the activities (A or B), than the behavior you are describing is WRONG.

And for all the ones which say that there is no problem with the documentation, try this:

  1. Create an application with Activity A (launching activity) & B (with the default launch mode for both).
  2. Start the application - a task is created with activity A only.
  3. From a button in activity A, launch activity B with a FLAG_ACTIVITY_NEW_TASK.
  4. Click the button several times and you'll see that activity B is created multiple times inside the task, which is NOT as the documentation says.

There are more scenarios to prove that the documentation is BAD / WRONG.