I'm starting a new thread on this, as I am now more clear on the problem I was having and this thread title is much more apt.
The historical thread is here: https://www.b4x.com/android/forum/posts/493849/
https://www.b4x.com/android/forum/posts/493849/
I now realise that when starting an app that is in the background by clicking the app icon, SOMETIMES the last activity is simply resumed, but other times the OS thinks that it's starting a second instance, and kills the first instance. When this happens, I get "Killing previous instance (Main)" in the log window, and I run into problems.
The problems:
The re-created Main activity runs, then if I click on an icon to enter another activity (one that was active in the session prior to going into the background and me clicking the app icon to return to it), then that activity does start up, but totally misbehaves. For example if I click the back button to return to the Main activity, this fails. So I think something has gone wrong with the stack, control is trying to go from my activity back to the OTHER main (that the OS killed).
I have no idea how to handle this.
I thought if I could somehow detect (in main) that the previous instance has been killed, maybe I could somehow destroy the instances of the other paused activities, so they'll be newly created.
Or somehow end this new activity and revert back to the old one before it gets killed.
The historical thread is here: https://www.b4x.com/android/forum/posts/493849/
https://www.b4x.com/android/forum/posts/493849/
I now realise that when starting an app that is in the background by clicking the app icon, SOMETIMES the last activity is simply resumed, but other times the OS thinks that it's starting a second instance, and kills the first instance. When this happens, I get "Killing previous instance (Main)" in the log window, and I run into problems.
The problems:
The re-created Main activity runs, then if I click on an icon to enter another activity (one that was active in the session prior to going into the background and me clicking the app icon to return to it), then that activity does start up, but totally misbehaves. For example if I click the back button to return to the Main activity, this fails. So I think something has gone wrong with the stack, control is trying to go from my activity back to the OTHER main (that the OS killed).
I have no idea how to handle this.
I thought if I could somehow detect (in main) that the previous instance has been killed, maybe I could somehow destroy the instances of the other paused activities, so they'll be newly created.
Or somehow end this new activity and revert back to the old one before it gets killed.