Android Question Fully exit app after invoking an external app with intent

JohnC

Expert
Licensed User
Longtime User
I am trying to write an app that will launch an external app via an Intent, then immediately have my app close.

But it seems like my app is not fully closing because sometimes when I rerun my app, it appears to skip over my app's UI and go directly to the screen of the external app I invoked with the Intent.

I set a breakpoint to see what's going on, and this jumping directly to the external app is not because my app is re-invoking the intent again. It seems like my app is just moving to the background and doesn't fully unload/close after it does the intent launch. So when I click my app's icon again, it simply comes to the foreground and jumps directly to the last "state" it was in, and that last state was displaying the external app.

So, after invoking an intent, what is the recommended code to make sure my app fully unloads after the intent so it will properly start from the beginning on it's next launch?
 

JohnC

Expert
Licensed User
Longtime User
This is really nuts....

I placed the breakpoint on the line of the StartActivity(iIntent), and it does trigger the first time I use my app and launches the external MMS app. But after the MMS app is displayed, if I then just hit the home button and then try to rerun my app from the IDE in debug mode, it will immediately display the MMS app and NOT my app's UI (and the breakpoint was NOT triggered), then after a short delay the IDE gives this error "Rapid Debugger Failed to connect to device".

But, if I instead press the "back" key when the MMS is being displayed to then hide the MMS app's screen, then trying to run my app again from the IDE will properly display it's UI.

So, why when launching an external app via Intent and leaving that external app open (hitting the home button instead of a back button), why does it prevent my app from running again even from the IDE? I thought the IDE fully kills any previous instance of my app from memory before launching it again from the IDE.

Oh, and when my app first runs and launches the MMS app, it does seem like my app fully exits/unloads because the IDE will return to the non-debug/edit mode after it launches the MMS app.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Upvote 0
Top