Search code examples
androidandroid-serviceandroid-service-binding

How to handle the necessity of interprocess communication in my Android application?


My application requires me to periodically do the following:

  1. Send periodic heartbeat information to a server, once per 15 seconds
  2. Take periodic screen captures and send them to a server, once per 60 seconds
  3. Send message to and poll the server for messages, once every 5 seconds

I've written the services for each of the items listed above but here is where I need help, communication between those services...

The heartbeat service needs to be able to:

  1. Get some information from the screen capture service.
  2. Queue a message with the messaging service.

The screen capture service needs to be able to do the following:

  1. Fetch the current activity from my application
  2. Queue a message with the messaging service.

The messaging service needs to be able to do the following:

  1. Receive messages to queue up to be sent to the server from my application/services
  2. Send messages received from the server to the application

With all of the communication pathways required, I'm wondering how to do that? Would I just bind my application to all of the services? Bind services to other services? Use some other from of communication?

I need all of those services to continue running/functioning even if my application isn't in the foreground.


Solution

  • Provided more info in chat, but the general thrust is:

    • use AlarmManager to schedule invokations of a broadcast receiver
    • let the receiver re-schedule itself when invoked
    • let the receiver send a command to the service (this will start the service, if it's not running already)
    • let the service spin a thread
    • do HTTP in the thread