【发布时间】:2014-02-23 20:03:16
【问题描述】:
我有一个片段:
public class myMap extends Fragment implements LocationListener
{
// do all the usual stuff
@Override
public void onResume()
{
super.onResume();
if(mIsGPSEnabled)
{
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, this);
}
// and of course a bit more of code I am skipping
}
@Override
public void onLocationChanged(Location location) {
Toast.makeText(getActivity(), "location changed " + location.getLatitude() + " " + location.getLongitude(), Toast.LENGTH_LONG).show();
}
我注意到以下行为:
- onResume 始终获取最后一个正常工作的已知位置。
- 在我的通知栏上启动应用程序时,我看到这个 GPS 处于开启状态的小图标
- 过了一会儿,我第一次调用了 onLocationChanged(到目前为止一切都很好)
- 现在,小 GPS 图标从通知栏中消失了,并且再也不会调用 onLocationChanged。该应用始终处于前台
- 我从不(暂时)取消注册我的位置更改监听器
- 我将我的应用程序置于后台并启动 osmand(一种导航软件),而该软件正在运行时,我在每次更新时都会在 onLocationChanged 中看到我的 toast,并且正常工作。
谁有想法?
【问题讨论】:
-
您确定它不是在请求更新吗?您将最短请求时间设置为 1 分钟,因此您至少在一分钟内不会收到更新
-
是的,我确定,在镇上等了 15 分钟...
-
你在 HTC Hero 上进行测试吗?
标签: android gps locationlistener