从Android OS 5.1.1自动停止的服务 [英] Services stopping automatically from android OS 5.1.1

查看:137
本文介绍了从Android OS 5.1.1自动停止的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发与Voip& amp;相关的应用程序IM(聊天应用程序)。到android OS 5.0为止,它运行良好,并且客户端也没有问题。但是从android OS 5.1.1开始,我们面临问题。



问题:




  • 如果应用位于前景,并且如果设备进入睡眠模式,则表示工作正常。

  • 如果应用处于后台,并且如果 10分钟后设备进入睡眠模式,则所有服务都会自动停止



测试:




  • 为了进行测试,我创建了一个计时器任务,每1分钟打印一次日志。因此,当我关闭该应用程序时(意味着该应用程序处于后台状态)


  • 直到 android OS 5.0 日志将连续打印。 / p>


  • android OS 5.1.1 开始,进入睡眠模式后,在10分钟后不再打印日志。计时器任务正在停止




我的应用程序也面临同样的问题。



进行了一些R& D之后,我就知道了打do睡模式和应用程序优化。是否与在后台自动运行停止服务有关。



如果可以,请让我知道如何解决此问题。

解决方案

这是Google为防止不必要的电池使用而做的新事物。
对于新版本,后台服务受到限制,以延长电池寿命。 android服务的消耗与在前台运行的应用程序几乎相同。因此,即使应用未运行,其服务也可能正在运行,并且正在使用内存和电池。



如果您必须使用任何类型的后台进程,请尝试使用作业计划程序可能对您有用。



工作计划程序将任务分组并根据我们在实现中提供的约束执行后台任务。
这有一个限制,它在最低的API 21上支持



要在较低版本上支持,可以使用 Firebase JobDispatcher 支持API 9。



我个人更喜欢 Firebase JobDispatcher



此< href = https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher- rel = nofollow noreferrer>链接可帮助您了解有关调度程序及其更多信息实施。


I am working on an application related to Voip & IM (chatting application). Till android OS 5.0 it is working good and no issues from client also. But from android OS 5.1.1 onwards we are facing issues.

Issues:

  • If the app is in foreground and if device goes to sleep mode it is working good.
  • If the app is in background and if device goes to sleep mode after 10 minutes all the services are stopping automatically.

Testing:

  • For testing I created one timer task to print logs for every 1 minute. So when I close the application (means if the app is in background)

  • Till android OS 5.0 logs are printing continuously.

  • From android OS 5.1.1 onwards after going to sleep mode, after 10 minutes logs are not printing. Timer task is stopping

Same problem I am facing for my application also.

After doing some R&D I came to know regarding doze mode and app optimization. Is it anyhow related to stop services automatically running in background.

If yes, can anyone please let me know how to overcome this issue.

解决方案

This is new thing which google done to prevent unwanted battery usage. For new versions the background services are restricted for better battery life. The android service consumes almost same as the application running in foreground. So even though app is not running its services may be running and using memory and battery.

If you have to use any kind of background process try to use Job Scheduler which may be something useful for you.

The Job Scheduler groups the task and execute the background task based on the constraints we provide in the implementation. This have a limitation it support on minimum API 21

To support on lower version you can use Firebase JobDispatcher which support from API 9.

I personally prefer Firebase JobDispatcher

This link help you to understand more about scheduler and its implementation.

这篇关于从Android OS 5.1.1自动停止的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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