I'm looking for a way to listen to a particular location in my database in every activity using one ChildEventListener
.
I have a shopping app, and I need to listen to the user's order status through the app to show alerts and save data locally.
I had 2 ideas in mind:
- I thought about attaching and detaching the listener in
OnResume()
andOnPause()
of everyActivity
, but the code will be duplicated in everyActivity
since it does the same job. - I thought about attaching one listener to the
MainActivity
, then send broadcasts to other activities, but this failed due toMainActivity
being destroyed
--
What is the best practice for listening to one node and keep app synchronized?