的是Android服务有用的,当我不需要进程间通信? [英] Is Android Service useful when I don't need interprocess communication?

查看:97
本文介绍了的是Android服务有用的,当我不需要进程间通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,当我不需要进程间通信,也几乎没有理由使用服务。我所知道的唯一的原因是这样的:如果我的进程有一个启动的服务,这个过程是不太可能被杀害

It seems that when I don't need interprocess communication, there's almost no reason to use a Service. The only reason I am aware of is this: if my process has a started Service, the process is less likely to be killed.

我可能只是有dontWantToBeKilled()和canBeKilled()方法的实用程序类,这将启动/停止的虚拟服务。除此之外,我不会使用服务。这是正确的?

I could just have a utility class with dontWantToBeKilled() and canBeKilled() methods, which would start / stop a dummy Service. Apart from that, I won't use Services. Is this right?

推荐答案

是的,还有其他的原因。

Yes, there are other reasons.

您的应用程序中,可以通过时,它需要更多的资源,系统杀死一个进程中运行。

Your application runs in a process which can be killed by the system whenever it needs more resources.

根据的正在运行的服务具有更高的优先级比不是在前台,这意味着系统更可能杀死具有在后台活动多于一个具有在后台运行的服务的应用程序处理的活性

According to this a running service has a higher priority than an Activity that isn't in the foreground, meaning that the system is more likely to kill an application process that has an Activity in the background than one that has a Service running in the background.

有关服务的文档指出:

如果该服务已经启动,那么它的托管过程
  被认为是比目前任何过程不那么重要
  可见在屏幕上的用户,但不是任何过程不是更重要的
  可见。因为只有少数进程通常是对可见光
  用户,这意味着服务不应除了在被杀死
  极端的内存不足的情况​​。

所以,你可以使用服务来减少你的应用程序被杀害的可能性。

So, you can use Services to decrease the likelihood of your application process being killed.

这篇关于的是Android服务有用的,当我不需要进程间通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆