Addy
Addy

Reputation: 85

Trigger a function when firebase notification receive while app is open

I have a question about firebase notification service. I send notification from firebase console it receive successfully and i user click on notification then i open "TrackinActivity", this work fine. But if user open app and stay on "TrackinActivity" and then firebase notification receive i want without any refresh in TrackinActivity a funtion is trigger in TrackinActivity. which change some values in TrackinActivity without refresh.

I mean in this function:

    @Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
}

i want to call a function of that tracking activity without refresh.

Upvotes: 1

Views: 196

Answers (1)

Abdur Rehman
Abdur Rehman

Reputation: 1327

for this you have to set a boolean variable in shared preference

for example isActivityOpened = true

set value false when you destroy "TrackinActivity" and set value true in onCreate of this activity

 @Override
 public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        if(isActivityOpened){//check sharedpreference

           //here send local broadcast message and receive in "TrackinActivity"
           //on receive method of local broadcast update some values in activity

        }else{

           //here start activity as usual 

        }
 }

for getting details about local broadcast

Upvotes: 1

Related Questions