android防止服务被杀死的最佳方法? [英] android best way to prevent service being killed?

查看:41
本文介绍了android防止服务被杀死的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旨在开发一个小应用程序来获取最新文章并在通知栏

aim developing a small app to get latest articles and showing them in notifications bar

我知道设置 service foreground 是个坏主意,因为它会消耗电池和设备内存

i know its bad idea to set service foreground coz its killing battery and device ram

正如我们所知,有一些应用程序每 x 分钟就会杀死所有正在运行的服务,例如 advanced task Killer,我的服务也被杀死了,所以在用户吃完应用程序之前不要让 abel 获取最新消息再次

and as we know there is some apps killing all running services every x minutes such as advanced task killer and my service has killed too so aim not abel to get latest news until the user lunch the app again

我在谷歌上搜索了如何防止我的服务被杀死我找不到一个好的解决方案,其中大多数都太旧了,其余的都没用

I've googled it how to prevent my service being killed i couldn't found a good solution most of them are too old and the rest are useless

我真的需要一个建议,有没有办法防止我的服务在没有 foreground 的情况下被终止?

i really need an advice is there any way to prevent my service being killed without foreground ?

非常感谢任何帮助

推荐答案

你可以做的是使用一个 AlarmManager 并安排一个 PendingIntent,它会定期唤醒并执行你的东西,就像描述的 此处.

What you could do is using an AlarmManager and schedule a PendingIntent that will periodically wakes up and execute your stuff, like described here.

这篇关于android防止服务被杀死的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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