2

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.

Gary Busey
  • 21
  • 2

2 Answers2

3

Add this to your activity definition in manifest...

android:launchMode = "singleInstance"

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

Community
  • 1
  • 1
Awais Tariq
  • 7,724
  • 5
  • 31
  • 54
2

I have answered such a question,you can declare android:launchMode="singleTask" attribute for your MainActivity in the AndroidManifest.xml file, so that the OS won't create a new instance if there is one running in the background.

Community
  • 1
  • 1
Huang
  • 4,812
  • 3
  • 21
  • 20