Skip to content Skip to sidebar Skip to footer

Android Launchmode="singletask" Does Not Work As Expected

I have an application that runs in the background, and displays an error message via the notifications system. This notification has a pendingIntent that leads back the the app's m

Solution 1:

You are almost answering your own question in the question ;)

Try using:

android:launchMode="singleInstance"

Be warned though, if you are doing anythign like startActivityForResult - you will never receive the result!

Update:

If you want to receive new intent data using onNewIntent:

public void onNewIntent(Intent intent)
{
    super.onNewIntent(intent);
    setIntent(intent);
}

That will change the intent the application returns when you use getIntent() to the new intent which was passed to onNewIntent.

Solution 2:

Solution 3:

It sounds to me like you want the following behaviour if the user selects the notification:

  • If the app is already running in a task, just bring that task to the foreground and show whatever activity happens to be on top of the activity stack.

  • If the app isn't already running in a task, launch the main activity of the app in a new task.

If this is the behaviour you are after, you don't need (or want) any special launch mode. See my answer to this question: Notification to restore a task rather than a specific activity?

This should do what you want.

Post a Comment for "Android Launchmode="singletask" Does Not Work As Expected"