我们怎样才能prevent从被杀害的操作系统服务? [英] How can we prevent a Service from being killed by OS?

查看:134
本文介绍了我们怎样才能prevent从被杀害的操作系统服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用服务在我的应用程序,它需要运行,直到我卸载应用程序,但问题是,它被杀死的操作系统。

I am using Service in my application and it needs to run until my application is uninstalled, but the problem is it gets killed by OS.

如何才能从prevent它被杀害的操作系统?或者,如果它被杀死了,我们才能再次重启该服务通过编程方式?

How can we prevent it from being killed by OS? Or if it gets killed can we restart that service again through programmatically?

推荐答案

您可能会遇到的<一个服务href="http://developer.android.com/guide/topics/fundamentals/services.html#Foreground">foreground使用<一个href="http://developer.android.com/reference/android/app/Service.html#startForeground%28int,%20android.app.Notification%29">startForeground().

一个前台服务是一个被认为是一些服务   用户积极知道,因此不为系统的候选   内存在低杀死。

A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on memory.

但请记住,一个前台服务必须为状态栏的通知(这里读),以及该通知不能被解雇,除非该服务被停止或删除从前景。

But bear in mind that a foreground service must provide a notification for the status bar (read here), and that the notification cannot be dismissed unless the service is either stopped or removed from the foreground.

注:这仍然不能完全保证该服务不会被极低的内存不足的情况​​下死亡。它不仅使得它不太可能被杀死。

Note: This still does not absolutely guarantee that the service won't be killed under extremely low memory conditions. It only makes it less likely to be killed.

这篇关于我们怎样才能prevent从被杀害的操作系统服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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