Android Question B4XPages runs in background but ... !

agraham

Expert
Licensed User
Longtime User
A B4XPages Android app will carry on running while in the background. Pause is called as it goes into the background and Resume when it is displayed again. However if it is destroyed while in the background, e.g. by removing it from Recents, it receives no notification so has no opportunity to save any state it changed while in the background.

I don't know if this is what Android does or whether it is possible to get an onDestroy event added so we can deal with this.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
I know, I just wondered whether Android gave any notice of destruction that could be used to save any changes made in the background.
In some cases you will get the TaskRemoved event in the starter service however in many cases there will be no event which means that B4XPage_Background should be the point where you save everything needed.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In some cases you will get the TaskRemoved event in the starter service however in many cases there will be no event which means that B4XPage_Background should be the point where you save everything needed.
I would like to add that it would be appropriate to "forget" the Starter service (don't create it). It is always advisable to develop an Android app thinking about the possibility of creating an iOS version as well. This is one of the great advantages of B4XPages (although there are many advantages to using them even wanting to develop only an Android app).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It will cause B4A to use the old unhandled exceptions method and show an unuseful dialog instead of letting the app crash with a proper crash report (or managed by the developer).

It is also good to have a consistent entry point to your app. Most apps will eventually use it for something.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Just a "curiosity"...

I'm running some tests. Great advantage, as I have already written, the fact that an app also still run in background, especially in my case, a turn-based game, so if I, after making my move, send the app in background, the websocket continues to receive data and the game continues as if the app were in foreground.

Small "problem": even the sounds still play šŸ˜
It will be necessary to stop them in this case.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
In some cases you will get the TaskRemoved event in the starter service however in many cases there will be no event which means that B4XPage_Background should be the point where you save everything needed.

what i don't yet have really clear, is the lifecycle workflow of background/foreground event:
does Background get called for every open page or just the MainPage, or just the topmost one?
so where it's best to save a global app configuration? in every page background event or just the main one?
 
Upvote 0
Top