我有一个包含活动和服务的Android应用程序.目前它们都存在于同一个进程中并使用相同的堆但我想要为服务分离进程/堆. IE浏览器.我希望服务完全独立于活动,这样如果活动崩溃,它将不会影响服务.但是,我希望它们可以作为单个应用程序安装.这可能吗?
解决方法:
绝对有可能.在AndroidManifest.xml中查看服务的process属性
http://developer.android.com/guide/topics/manifest/service-element.html
报价:
The name of the process where the service is to run. normally, all components of an application run in the default process created for the application. It has the same name as the application package. The element’s process attribute can set a different default for all components. But component can override the default with its own process attribute, allowing you to spread your application across multiple processes.
If the name assigned to this attribute begins with a colon (‘:’), a new process, private to the application, is created when it’s needed and the service runs in that process. If the process name begins with a lowercase character, the service will run in a global process of that name, provided that it has permission to do so. This allows components in different applications to share a process, reducing resource usage.