【发布时间】:2013-09-10 02:16:23
【问题描述】:
我在我的应用程序中使用Google Play Services,以便我可以使用Location 功能。我已阅读文档,但不清楚当我运行位置更新并离开应用程序时会发生什么。
位置更新是否仍会在后台进行?如果没有,我该怎么做?
【问题讨论】:
标签: java android google-play-services android-location
我在我的应用程序中使用Google Play Services,以便我可以使用Location 功能。我已阅读文档,但不清楚当我运行位置更新并离开应用程序时会发生什么。
位置更新是否仍会在后台进行?如果没有,我该怎么做?
【问题讨论】:
标签: java android google-play-services android-location
位置更新是否仍会在后台进行?如果没有,我该怎么做?
我为我的应用所做的就是继续使用后台服务跟踪位置。此外,您可能希望启动该服务并将其标记为前台,以便向用户显示您正在跟踪手机位置的通知。
【讨论】:
Service 并在后台更新它有点困惑。
请确保在您离开应用程序时删除LocationListener,通常我将其放在Activity 的onPause() 方法中,否则由您自己处理是否应该这样做。下面是示例代码:
@Override
protected void onPause() {
locationMananger.removeUpdates(this);
// with "this" is your Activity implementing the LocationListener
super.onPause();
}
希望这会有所帮助。
【讨论】:
Service 以使用单独的进程在后台运行并更新您的位置。这里是从Service: vogella.com/articles/AndroidServices/article.html 开始的地方。希望这会有所帮助。