0

I have a widget which can pop up small dialogs when clicked. These dialogs are displayed by an activity called RemoteActivity in singleInstance launchMode. In one of these dialogs, there is a button to launch the main app MainActivity, which has the standard launchMode.

However, when this button is clicked, and startActivity() called, MainActivity isn't launched, although I can see the corresponding "Starting activity: Intent { ... }" in logcat.

If I set the launchMode of RemoteActivity to standard then MainActivity gets launched, but this isn't what I want, RemoteActivity is merely an extension of the widget, I don't want it to stack with any other activity.

I also tried with FLAG_ACTIVITY_NEW_TASK but it didn't help, and it shouldn't be necessary anyway according to the docs:

A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.

How can I launch my main activity?

UPDATE / ERRATA:

The MainActivity is actually launched but only if it isn't already part of a task. If I launch MainActivity normally through the launcher, and press Back to exit, then RemoteActivity does launch MainActivity.

But if, instead of pressing Back, I press Home to leave MainActivity, then RemoteActivity can't launch MainActivity, although the intent appears in logcat.

I'm testing this on Froyo.

Any idea of what's happening?

olivierg
  • 10,200
  • 4
  • 30
  • 33

2 Answers2

0

Maybe the noHistory flag will work for what you are looking for?

Jonas Schmid
  • 5,360
  • 6
  • 38
  • 60
  • I've just tried to add noHistory to RemoteActivity and it doesn't help. I'm not going to add it to MainActivity, I don't want this, it must part of the history. By the way, there is a subtlety, please see my "update". – olivierg Apr 27 '11 at 13:44
0

I found the problem: this behavior only occurs when calling finish() before startActivity() in RemoteActivity. If I call startActivity() before finish() then it works fine whether MainActivity is already part of an existing task or not.

Go figure...

olivierg
  • 10,200
  • 4
  • 30
  • 33