views:

103

answers:

0

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)

  1. User Launches App
  2. Activity A starts (depending on auto-login or not, it launches activity B)
  3. Activity B starts
  4. User chooses an action
  5. Activity C starts
  6. User hits Home

Desired Case 1

  1. User does other stuff
  2. User launches App
  3. Activity C resumes
  4. User hits back
  5. Activity C destroys and Activity B starts on activity result

Desired Case 2

  1. User does other stuff
  2. OS kills all but root activity to free memory
  3. User launches App
  4. Activity A starts
  5. User may need to login depending on autoLogin
  6. Activity B starts

Desired Case 3

  1. User does other stuff
  2. User gets a Notification
  3. User clicks Notification
  4. Activity C and B destroy
  5. Activity A starts
  6. Pending login required or not
  7. Activity B starts
  8. User hits Back
  9. Activity B Destroys
  10. 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