views:

25

answers:

1

This has probably been asked before, but I can't find a good way of implementing it. I'm trying to write a program that manages a form of messages, and these messages are received from an external data source. This all works. However, the problem comes when I try to notify the user: I would like to have the notification jump directly to the message when it is touched, but this seems to mess up the back stack. This is probably best explained by example:

  1. I open up the message list, the main activity, and browse for a while.
  2. I hit home and go into another app (let's say Music).
  3. A new message is received. A notification comes up, which I touch. The message detail view is displayed.
  4. Now I hit Back. What I want to have happen is that I return to Music, but unfortunately, Back sends me to the message list, and then hitting Back will return me to music.

The both the list and the detail activities are marked as "singleTop", and the exact flags that I use for the notification Intent are:

  • FLAG_ACTIVITY_NEW_TASK
  • FLAG_ACTIVITY_CLEAR_TOP
  • FLAG_ACTIVITY_SINGLE_TOP

I figure if the Messaging application can do this, why can't I?

A: 

I have found one way to do this, but it's still not ideal:

  • Change the detail activity to have a different task affinity from everything else.
  • Add android:launchMode="singleTop" and android:excludeFromRecents="true" to the detail activity's manifest entry.
  • (Optional) Modify the list activity to open the detail activity with FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET. (This makes the task more like the built-in messaging app.)

The only fault to this scheme is that switching back over to the app will always go back to the list activity, but at least it is consistent. If someone else has a better way to do this, I'd love to hear it.

Quartz