在最小化应用程序时暂停定位服务? [英] Pause Location services when app is minimized?

查看:212
本文介绍了在最小化应用程序时暂停定位服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前有一个应用程序,其中一项活动正在运行时使用位置更新.但是,当用户最小化应用程序,回家或进行其他活动之前,我想暂停/停止定位服务,直到我再次需要该位置为止.我不想停止该应用程序,因为可能会有一些持续运行的数据.我只想在最小化应用程序的同时停止位置更新.然后,当应用程序重新打开时,我想再次开始服务.拜托了,谢谢!

I currently have an application that uses location updates when one of the activities is running. However, I want to pause/stop location services when the user minimizes the application, goes to the home, or moves to another activity until I need the location again. I do not want to stop the app, as there can be some continually running data. I just want to stop the location updates while the app is minimized. Then when the app is reopened, I want to begin the services again. Please and Thank You!

推荐答案

只需将开始和结束代码添加到活动onResume和onPause方法中即可.

Just add the starting and stopping code into the activities onResume and onPause methods.

没有源代码可以查看,很难为您提供详细的答案.

Without having source code to look at it's hard to give you a detailed answer.

如果您在此处使用android文档: http://developer. android.com/training/location/retrieve-current.html

if you're using the android docs here: http://developer.android.com/training/location/retrieve-current.html

相关方法应该是

mLocationClient.connect();

mLocationClient.disconnect();

这篇关于在最小化应用程序时暂停定位服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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