We're having trouble getting our notifications and launch modes to run properly. First let me describe the behavior that we want.
Our main and launcher activity is Activity.Login (Lets call this A) The next activity is always MainListActivity (Lets call this B)
- User Launches App
- Activity A starts (depending on auto-login or not, it launches activity B)
- Activity B starts
- User chooses an action
- Activity C starts
- User hits Home
Desired Case 1
- User does other stuff
- User launches App
- Activity C resumes
- User hits back
- Activity C destroys and Activity B starts on activity result
Desired Case 2
- User does other stuff
- OS kills all but root activity to free memory
- User launches App
- Activity A starts
- User may need to login depending on autoLogin
- Activity B starts
Desired Case 3
- User does other stuff
- User gets a Notification
- User clicks Notification
- Activity C and B destroy
- Activity A starts
- Pending login required or not
- Activity B starts
- User hits Back
- Activity B Destroys
- Activity A Destroys
Unfortunately, when we launch the app from a Notification (the intent is for A with the NEW_TASK flag), we end up with something like A-B-A, which is something we don't want. Instead, we expected the same behavior as clicking on the icon from the app panel.
After some reading we tried setting the activity as singleTask in the manifest. This fixes the A-B-A problem, but now whenever we relaunch the app from anywhere (app panel / notification) the stack is cleared and you always start out from A. The singleTask behavior appears to be different from what was described in the documentation. According to Jotobjects on a android-developers post, it seems the following happens with launchmode singletask:
"RECAPPING THE ORIGINAL SUBJECT: + For launchMode=singleTask if there is an intent_filter in the manifest the task stack is always cleared after returning to Home and re-launching (returns to main activity instead of last activity). "
But the documentation recommends always using singleTask with intent filters MAIN and LAUNCHER; wouldn't this always cause the task stack to clear even when it shouldn't?
To be clear, the case that is failing for us is case 1.
<activity android:name=".Login"
android:launchMode="
singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainListActivity"
android:label="@string/app_name">
</activity>
Here's how the notifications launch as well:
int icon = drawable.notice;
tickerText = "CloudList: New Updates";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
context = getApplicationContext();
contentTitle = "CloudList Updates";
Intent NotificationIntent = new Intent(this, Login.class);
// NotificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this,
0,
NotificationIntent, 0);
contentText = "You have " + String.valueOf(notifyFriends) + "
friend requests.";
notification.setLatestEventInfo(context, contentTitle,
contentText, contentIntent);
mNotificationManager.notify(NOTIFICATION_NEW_FRIENDS,
notification);
Any help/advice/suggestions would be appreciated. Let me know if more information is needed as well
Thanks, Andrew