Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android launchmode="singleTask" does not work as expected

Tags:

android

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 main screen. On this main screen, I have set launchmode="singleTask". As I understand it from the Android Dev Guide, this should mean that my main activity will only ever have one instance.

However, if the user is viewing that activity at the time (or another one within the app), and goes and touches the notification to clear it, it goes ahead and puts another copy of the activity on the stack, so if I hit the back button, it will return to the main screen again (from the main screen).

Why would it be doing this?

like image 408
Ogre Avatar asked Nov 12 '10 21:11

Ogre


1 Answers

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.

like image 51
Scoobler Avatar answered Nov 15 '22 15:11

Scoobler