3

I have an Activity that starts a local Service for background operation.

They both resides on the same process, so the communication between them should be simpler.

However, I don't understand how to implement the communication according to my needs:

Activity's behavior:

  • On creation, check if the service is already running:

    • If it is already running, disable Start button, and enable Stop button.
    • Otherwise, enable Start button, and disable stop button.
  • When Start button pressed: start the service, and wait for notification from the service that it finished its internal initialization. (can take more than 10 seconds)
  • When Stop button pressed: stop the service.

My problem is how to make the Activity listen to the Service without busy-waiting.

I could use IBinder according to this link, but I will have to busy-wait.

I will be glad for suggestions.

barak1412
  • 972
  • 7
  • 17

1 Answers1

2

You can check this link to see if service is running How to check if a service is running on Android? in case of communication you can use localbroadcast

Community
  • 1
  • 1