I have a service listening to some events from server. A service has START_STICKY flag that makes him restart when it\'s killed by OS. When service receive an event i have two s
It sounds like you are using LocalBroadcastManager
. That's good. Its sendBroadcast() method returns a boolean indicating if a registered receiver was found. You can use that result to determine if your receiving activity (MainActivity) exists and has registered to receive the broadcast.
When your service has an event to send to MainActivity, first try to send the event using sendBroadcast()
. If it returns true, your done. If it returns false, the activity is not registered and must be created using startActivity()
, with the event passed as an extra, as shown in your posted code.