I have an heir to Service and heir to BroadcastReceiver .

How in real-time service to catch events that occur in BroadcastReceiver to respond to them? You must listen to the listener :)

It comes to mind only thread with a time cycle in the Service which will periodically check the state in the BroadcastReceiver but then the same can be done without the BroadcastReceiver . Or maybe you need to create some kind of common interface?

    1 answer 1

    Transfer the intent (into which the necessary data was onStartCommand() ) from the BroadcastReceiver into the service and parse / process in onStartCommand() .

    • Thank. Good idea. - Bogdan Shulga
    • Hmm ... I was onStartCommand() here ... onStartCommand() started at the start of the service and can receive the content only at the start. And if my service is constantly running and monitoring BroadcastReceiver ? - Bogdan Shulga
    • one
      return START_STICKY try onStartCommand() - VAndrJ
    • And what will it give? If the service is killed, the system will restart it ... This is of course good. But the service must constantly respond to new alerts from the BroadcastReceiver without restarting. - Bogdan Shulga
    • one
      onStartCommand() is called for each intent, it doesn't matter if the service has already been launched or not - xkor