views:

57

answers:

2

I start an Activity from my Widget, which should start a special view.
But if the app is already running (not left with back button), Android instead activates the activity that was last shown.
Is there any flag or other way to avoid this behaviour?
Closing the previous activity wouldn't be a problem in my app, there's no user input that would be lost.
I tried a workaround with finish() in onStop(), but onStop is also invoked when a sub activity (startActivityForResult) is invoked, so returning from there returns to nothing - the app would be closed.

A: 

Try android:clearTaskOnLaunch="true" in the manifest of the activity containing the "special view".

CommonsWare
Sadly, this doesn't work. I even tried using different "taskAffinity"s, finishOnTaskLaunch, allowTaskReparenting, FLAG_ACTIVITY_CLEAR_TOP, and FLAG_ACTIVITY_RESET_TASK_IF_NEEDED. (FLAG_ACTIVITY_NEW_TASK is set anyway of course, since the app might not be running.)
M. Schenk
A: 

I had this problem too and solved it by using android:launchMode="singleInstance" in each of my activity declaration.

Rob