Android Question Push Notification and application state

iCAB

Well-Known Member
Licensed User
Longtime User
I am trying to figure out the best way to handle push notifications in a multi-activity application.
What I would like to be able to do is the following:

1. if the application is running in the background, bring the application to the front, keeping the same activity open, and fire an event indicating that a push message was received. It would also be nice to determine which activity is current active in this case

2. if application is not running, launch the application .

#2, launching the application is not an issue, however determining the application state:
Running background, running foreground or not running is the issue I am trying to address.

Thanks in advance
 

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

This is what I have done and it seems to be working.
Can you please confirm if it is the right approach

In Push Service, I declare
B4X:
Public ActiveActivity As Object = Null

As suggested above, in activity resume I update
B4X:
Starter.ActiveActivity = Me

When a Push message is received I check

B4X:
    If PushService.ActiveActivity = Null Then
        Log("Application Not Running")
    Else
        Log("Application Running")
    End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…