Android Question B4x Pages - Process won't stop running after closing and restarting app

EstasPerplejo

Member
Licensed User
Hi all.
I am currently stuck with a problem that a user of my app told me about...
Using B4x Pages, Android 15:

Here is the problem :
User starts the app and then closes the app intentionally right in the middle of a page while several processes are still running.

He then restarts the app but all the sounds for instance from the page that was shut, can still be heard.
Other processes of the previous page before the restart are obviously still running also.

Is there a way to stop these processes in the mainpage after restarting the app?

I'd be grateful for any suggestions - thanks.
 

EstasPerplejo

Member
Licensed User
Hi Erel.
Well, Erel - you are right as far as moving an app to the background, this works just fine. The app starts where it was left off and is not restarted.
But that's not what I was talking about.
I really meant CLOSING the app!
Android 15 and atleast on my Pixel 8, the OS offers the option to CLOSE the app - Not moving it to the background or anything else. I suppose when Android says "Closing App" , they actually mean quitting an app, for good.

After closing an app that way, you need to restart the app and it runs as if you started it fresh. And here comes the problem: Although, seemingly the app behaves as if it was newly started, part of it is still running in the background.
You can here it, as sounds are still playing from one the the pages that was previously started.

That means to me: The app has not been properly closed by the OS or B4x.

Wouldn't you agree?
 
Upvote 0

EstasPerplejo

Member
Licensed User
I found an article in the web that describes this topic:

In Android 15, apps might appear to not fully close due to changes in how the system handles stopped apps and background activity. While swiping an app away might seem like it closes it, the app might still be in a stopped state, allowing it to resume quickly when reopened, but not actively running. This behavior is intentional to improve performance and battery life.

Here's a breakdown of why this is happening and how to manage it:

Stopped State:

Android 15 introduces changes where apps are only removed from the "stopped" state through user action or when the system needs to reclaim resources. This means that even if you swipe away an app, it might still be in a stopped state, ready to quickly resume when needed.

Background Activity:
Apps can also run in the background, performing tasks even when not actively in the foreground. While you can close the app's window, the background processes might still be active.
 
Upvote 0

EstasPerplejo

Member
Licensed User
Basically, the last sentence describes what happened to my app when the user stops the app that is still running a process which has has not completed.

And this brings me back to my original question. After restarting a "closed app", is there a way I can react to this by closing or restarting the page which is obviously still running?
Or can I gracefully close all processes involved, when a user closes the app this way?
 
Upvote 0

EstasPerplejo

Member
Licensed User
Well, so I did...
Result is, that the Page Manager returns a message in the logs saying: Page disappeared!
On both cases, the PageManager treats either case with the same message.

There seems to be no way to intercept closing the app and reacting to this in order to gracefully finish a running process. It just keeps running in the background. Even if I restart the app and call that page again, there is no way to stop the process...
Timers and sounds that were previously started within that page can't be stopped, no matter what I do.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Erel requested you to post the IDE logs.
Right click, copy to clipboard and paste on here.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
This is not only related to Android 15, I had the same problem on all my apps (on all android versions) that need to restart after change settings, to do a clear reinitialize.

The only way I found is to put a message box that inform the user to manually force close the app from android system. And this a big problem to me too, I never solved.

In past I had the problem to adapt my apps to work in background, now with B4XPages I have the opposite problem, they works good in background, but I have to manually force stop to get a fresh start.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Maybe I misunderstood, but it seems to me that you should "simply" stop "special objects" in the B4XPage_CloseRequest events. That is, if I have an audio player on a particular page, I'll stop the player in that event on that page.

I assume (hope) that event also fires when the user or the operating system brutally kills the process.

P.S. No, the event doesn't fire. Perhaps you could use the Starter's Service_Destroy / Service_TaskRemoved / Application_Error events, but that's only for Android.

P.P.S. No, those events don't happen either.
 
Last edited:
Upvote 0

EstasPerplejo

Member
Licensed User
Thank you for the replies.

Max123:
Well, I don't fully agree. With B4x Pages, you can react to nearly all events of a user input. So, if a user makes changes to some settings that affect one or more pages, you can react to this programmatically.
In my above mentioned case, the situation is quite different and it is due to a change in Android 15.
The OS offers the user the option to close the app BUT the app can't intercept this - at least so far I haven't found a way to intercept this.

LucaMs:
Good point, I tried this and unfortunately to no avail. Once the user closes the app, the OS seemingly prevents all other actions to intervene, and finishes off the app by itself.
 
Upvote 0
Top