微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何创建使用单独进程的Android活动和服务

我有一个包含活动和服务的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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐