开发者

How to enforce activity if app is running?

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 开发者_如何学Pythoninstead 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.


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


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


Call intent with FLAG_ACTIVITY_NEW_TASK and on main activity add:

android:launchMode="singleTask" android:clearTaskOnLaunch="true"

On the others add:

android:finishOnTaskLaunch="true"

This way it will kill off any activity when returning to the app after being in background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜