1

I have almost the same requirements as this excellent question:

Send data to activity with FLAG_ACTIVITY_REORDER_TO_FRONT

However, I'm using FLAG_ACTIVITY_NEW_TASK because each of my primary activities needs to run as a new task. In my testing onNewIntent isn't called in this case (even when activity already running). So how do I pass data to it?

I can get onNewIntent to be called, by setting launchMode to singleTask, however then I run in to this bug: Android: bug in launchMode="singleTask"? -> activity stack not preserved

I want to accomplish:

  1. If no instance exists, create a new instance, as a new task, and pass it data. (this part already works, I can get the data in onCreate)

  2. If an instance already exists, bring the task (entire task, not just root/one activity) it is in to the front, and:

  3. If task currently has a child activity displayed, do nothing

  4. If task doesn't have a child activity displayed (just root/main activity), process the passed data and update the UI

I have one task with a button, "Go to Event", when clicked it needs to open/start the Calendar task and highlight a specific event (but the Calendar will ignore that request if another activity is being displayed over the top of it).

Community
  • 1
  • 1
eselk
  • 6,764
  • 7
  • 60
  • 93
  • When I say "Calendar task" above, I'm referring to a task in my own application, not the built-in Calendar app or any other calendar app. – eselk Jun 22 '15 at 22:31
  • Can't you just pass in a bundle of extras with your intent? – Kristy Welsh Jun 22 '15 at 22:34
  • That's what I do, and covers #1. I can't figure out #2 (and 3 and 4) because onNewIntent isn't called, so how do I get the bundle if my activity is already running? – eselk Jun 22 '15 at 22:52
  • 1
    Have you tried the workarounds described in the accepted answer to [this question](http://stackoverflow.com/questions/11551195/intent-from-notification-does-not-have-extras)? – Bob Snyder Jun 23 '15 at 03:24

1 Answers1

1

Thanks to @qbix's comment, I found this answer:

Add Intent.FLAG_ACTIVITY_SINGLE_TOP -- which seems like it wouldn't be valid when combined with FLAG_ACTIVITY_NEW_TASK, but it works. It achieves all behaviors I listed above, and only fires onNewIntent if the activity is at the top of the stack, so I don't even have to worry about detecting that and ignoring.

More details here, even though this Q&A is related to PendingIntent and notifications:

Intent from notification does not have extras

Community
  • 1
  • 1
eselk
  • 6,764
  • 7
  • 60
  • 93