简体   繁体   中英

How to prevent Android application from loading multiple times?

This must be an easy one but I'm not having much luck searching for an answer. Apologies if this is a regular question.

If I navigate away from my app I cannot return to it. Starting the app again will load a second instance of it rather than returning to it. If I leave an audio loop running in my app, It's hard to get back in and turn it off.

On startup I'd like the app to destroy any previous instance of itself left running.

I'd also like to try having the app shut itself down when I navigate away (I know it's not the right way to do things but I'd like to try this for my own personal use of the app). Or have the "back" button destroy the app.

Thanks.

Add this to your activity definition in manifest...

android:launchMode = "singleInstance"

How to prevent the activity from loading twice on pressing the button

我已经回答了这个问题 ,您可以在AndroidManifest.xml文件中为MainActivity声明android:launchMode="singleTask"属性,这样,如果在后台运行一个实例,则操作系统将不会创建新实例。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM