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/heap for the service. Ie. I want the service to be completely independent of the activity so that if the activity crashes it won't affect the service. I do, however, want them to be installable as a single application. Is this possible?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
Definitely possible. See the
process
attribute forservice
inAndroidManifest.xml
http://developer.android.com/guide/topics/manifest/service-element.html
To quote:
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.