How to create an Android Activity and Service that use separate processes

前端 未结 2 559
南方客
南方客 2020-11-30 09:55

I have an Android app that consists of an activity and a service. Currently they both exist in the same process and use the same heap but I want have to separate process/hea

2条回答
  •  独厮守ぢ
    2020-11-30 10:40

    IPC for services is IMHO only required if the service should be consumed by other applications.

    Running a service in its own process has the small advantages that the garbage collector for the service does not affect your application and that the memory footprint of the service is a bit smaller if it runs alone.

    If consumption of the service by other applications is not a requirement for you, prefer a local service. Alternatively you can still run the service in its own process and use different communication with your application, e.g. via a broadcast receiver. I tried to describe the different approaches in my Android service tutorial under the following link: Activity and service communication.

提交回复
热议问题