Skip to content

Using a seperate process

Devrath edited this page Apr 16, 2024 · 5 revisions

Add the process tag in the manifest

  • We mark the service to be run in a separate process as below
<service android:name=".service.PlayerService"
         android:process=":playerprocess"/>

Use messenger for communication

By the below way, a messenger can be passed between the Activity and Service as a binder.

  • Return messenger reference instead of IBinder reference
  • A messenger is just a reference to a handler.
  • Basically when you create a messenger we pass a handler during the creation.
  • A messenger can be transformed into a binder.
  • A messenger can be created from a binder.

How it works

  • Create a Handler to handle the messages to be sent into Service.

Clone this wiki locally