mohamadreza jafarzade

05/03/2021, 9:07 AM
Hi. I have a FirebaseMessagingService and i want to update a running activity when special message comes from firebase. How i can do that?
😶 5

balaji sunku

05/03/2021, 9:26 AM
Your major challenge is not the push notification part. Your major challenge is how will you know what is the current running activity on the screen (when your app is not on foreground). You need device administration permissions for that. Once you figure it out, doing it when you receive a push notification is a cake walk .. Good luck in exploring the same.

mohamadreza jafarzade

05/03/2021, 9:32 AM
I think you misunderstand me. The problem is not to find the current activity from service. although, I have done it before and It does not require any permission and I only use ActivityManager to do that.
I just have searched and I have found two solution for that: 1. use EventBus library 2. register a BroadcastReceiver in my activity and send broadcast to handle it in activity. which solution is better? Is it safe to use EventBus library for only one usage?
😶 6


05/04/2021, 5:15 PM
You could have a Global SharedFlow attached to the application class and then just get a handle to it from the activity. The activity or it's ViewModel collect from that flow.
If you look at the docs for SharedFlow they show you how to use it as an event bus.