如何创建使用单独进程的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.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...