1

My understanding was that a singleTask activity, if it exists already, is not going to be created again, but its onNewIntent is going to be called.

In fact, that's what happens when I start an Intent from another Activity, but not from a service.

Furthermore, I noticed that this doesn't happen if I declare my Activity to be singleInstance (i.e in this case, even from a service onNewIntent does get called) but it also involves back stack complications that I don't want.

My undesrtanding was that onNewIntent would always be called, if I have an instance of the singleTask Activity running, and it does work that way from an Activity but not a service.

Why is that, and what should I do to keep my back stack intact and just bring my existing activity to the top from my service?

Note: I do have the FLAG_ACTIVITY_NEW_TASK when I call my singleTask Activity.

Thanks!

Grégory Jourdan
  • 367
  • 3
  • 12

3 Answers3

0

I tested and onNewIntent is called when launched from a service. I think what happens is your task was killed by the system, thus when you launched from the service a new task is created and thus onNewIntent is not called.

Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
  • Thanks but I do have this flag already... I'll add it to the description though :) – Grégory Jourdan May 03 '13 at 01:11
  • It seem to me that singleTask would clear top when called from activity. I test using A singleTask and B a normal activity. A --> B --> A when back press I expect B but I got my launching activity. From B I launched A normally and also with FLAG_ACTIVITY_NEW_TASK – Hoan Nguyen May 03 '13 at 01:31
  • It does clear top but it does so by re-creating the Activity instead of bringing it back to the top, and only in the combination of singleTask and "called from a service" which I don't get... – Grégory Jourdan May 03 '13 at 15:38
0

So it seems I can solve my problem by not making my service answer the HOME intent.

I should have mentioned that: my services gets the home intent, then launches the actual activity that I want to see. I couldn't find a way to have it not wipe the previous instance of that activity, without using singleInstance for it.

So as of now having the activity itself handle the HOME event seems to prevent re-creation (possibly because the service was destroying everything else when getting a home intent). I'm not 100% sure I get all the inner-workings of this, but it seems fine enough a solution.

Grégory Jourdan
  • 367
  • 3
  • 12
0

I saw this question while trying to solve a similar problem. I answered with my solution to this problem in a different thread, maybe the same response can be useful in this thread: Intent with old extra in onCreate() for singleTask Activity

Community
  • 1
  • 1
rodolk
  • 5,606
  • 3
  • 28
  • 34