服务是不活动的几小步舞后停止 [英] Service is stopped after a few minuets of inactivity

查看:215
本文介绍了服务是不活动的几小步舞后停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写使用(除非该服务已在运行)创建的主要活动时所启动的服务的GPS位置提供一个Android应用程序。我是IM pression该服务将继续与不可能例外是任务管理器可以杀了它,如果有一个内存不足下运行。由于某些原因,如果有一段非常低的活性,无论多少内存是可用的服务被重新启动。当用户外面,GPS是能够解决的位置,该服务将获得一个位置,每30秒,关闭GPS之间(以节省电池)。在这种情况下,服务将继续运行没有任何问题,但是当一个用户内移动和一个全球定位系统位置不能在五秒钟内可以找到,则服务关闭GPS和将只重新激活的GPS每200秒检查用户在户外搬回。在这种情况下,服务有时将被停止,并且将不被重新启动之前,该应用被重新打开,并且活动重新启动该服务。我创建了一个单独的服务,以确保这个过程是不间断的。没有人知道为什么这可能发生?非常感谢您的帮助! -dom

I am writing an android app using the GPS location provider in a Service that is started when the main Activity is created (unless the service is already running). I was under the impression that the service would continue to run with the unlikely exception that the task manager could killed it if there was a memory shortage. For some reason the service is restarted if there is a period of very low activity regardless of how much memory is available. When the user is outside and the GPS is able to resolve a position, the service will get a position every 30 seconds and turn off the gps in between (to save battery). In this case the service continues to run without any problems but when a user moves inside and a gps position can't be found within five seconds, then the service turns off the gps and will only reactivate the GPS every 200 seconds to check if the user has moved back outdoors. In this case the service will sometimes be stopped and won't be restarted until the app is reopened and the activity restarts the service. I created a separate service to make sure the process was uninterrupted. Does anyone know why this might be happening? Thanks so much for your help! -Dom

推荐答案

我想看看马克·墨菲的例子,与服务和Wakelocks涉及:

I would have a look at Mark Murphy's example that deals with Services and Wakelocks:

WakefulIntentService

如果你不能从他的code例如看着办吧,那么你要得到他的高级Android的书,其中的问题进行了详细解释。

If you can't figure it out from his code example, then you want to get his Advanced Android book where the problem is explained in detail.

的忙codeR指南先进的Andr​​oid开发

这是一些关于Android开发也是值得最小的成本,最好的书。

These are some of the best books on Android development and well worth the minimal cost.

这篇关于服务是不活动的几小步舞后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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