Android Question [B4XPages] Handle page-indipendent function in Main (Pause, Resume, ...)

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone,
i need to put some code in the Main Activity with B4XPages because i need to handle the _Pause event, _Resume event, etc... and do things that are not page related (reason why i don't need those events in a particular B4Xpage).

Similiar to what happends in iOS in the Main with Application_Active etc...

Example:
I send a notification, in the FirebaseService a need to know if the app is in background or not, so i thought to do like so:

B4X:
    If IsPaused(Main) == False Then
        ...
    Else
        ...
    End If
but this does not work because of this:
** Activity (main) Pause event (activity is not paused). **

So, in conclusion, how can i test if my app is in background?
Thanks in advance
 

Sandman

Expert
Licensed User
Longtime User
I do a little something-something when the app goes to background, and I just added the code to Activity_Pause in Main. Works great. That doesn't work for you?
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
I do a little something-something when the app goes to background, and I just added the code to Activity_Pause in Main. Works great. That doesn't work for you?
i hoped for something more intuitive, like -> the app goes in pause, and IsPaused return True 😂 😂

I think the story will end in a variabile setted in the Main_Pause actually
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
i hoped for something more intuitive, like -> the app goes in pause, and IsPaused return True 😂 😂
Yeah, I think you're missing a somewhat central point here: You know the place where you want to run the IsPaused(Main)? If the app is paused, that doesn't run. So... Yeah, that's a solid nope. :)

You either need to catch this on the way out, in Main. Or in the delegated events in each B4XPage. Setting a flag is fine, but don't expect any code to be able to read it while the app is paused. Also remember that the app can very well be killed - KILLED! - when it's paused, so if the flag is important, you should store it somewhere safe and not just in memory.
 
Upvote 0
Top