当我需要位置 android 时出错
我有一个问题。在我的应用程序中,我需要用户的当前位置。当我们有一个位置时(当我使用 locationManager.getLastKnownLocation 获取位置时)它工作正常,但是当我重新启动手机并且位置消失(我认为现金是空的)时,我得到此日志并强制关闭应用程序按钮。我点击一个按钮,我的应用程序重新启动,然后它工作正常...... 我现在的问题是返回 null 的位置... 这是日志:
08-25 10:02:55.000: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:55.449: DEBUG/libgps(2006): onUnsol: cmd 0x04 plen 57
08-25 10:02:55.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: num_sv 0
08-25 10:02:55.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: used_in_fix_mask 00000000
08-25 10:02:55.503: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:55.503: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:55.503: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:56.006: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:56.006: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:56.006: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:56.449: DEBUG/libgps(2006): onUnsol: cmd 0x04 plen 57
08-25 10:02:56.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: num_sv 0
08-25 10:02:56.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: used_in_fix_mask 00000000
08-25 10:02:56.505: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:56.505: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:56.505: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:57.009: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:57.009: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:57.009: ERROR/GPS(2006): gen_timer_add_locked
I have a problem. In my app i need current location from a user. It works fine when we have a location(when i get a location usig method locationManager.getLastKnownLocation), but when i restart my phone and location disappear (cash is empty i presume) i get this log and force close app button. I click on a button, my app restarts and then it works fine...
I now that a problem is with location that return null...
This is the log:
08-25 10:02:55.000: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:55.449: DEBUG/libgps(2006): onUnsol: cmd 0x04 plen 57
08-25 10:02:55.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: num_sv 0
08-25 10:02:55.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: used_in_fix_mask 00000000
08-25 10:02:55.503: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:55.503: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:55.503: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:56.006: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:56.006: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:56.006: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:56.449: DEBUG/libgps(2006): onUnsol: cmd 0x04 plen 57
08-25 10:02:56.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: num_sv 0
08-25 10:02:56.449: DEBUG/libgps(2006): oem_unsol_gps_measurement: used_in_fix_mask 00000000
08-25 10:02:56.505: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:56.505: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:56.505: ERROR/GPS(2006): gen_timer_add_locked
08-25 10:02:57.009: DEBUG/libgps(2006): request_location_fix_callback: session status 1
08-25 10:02:57.009: DEBUG/libgps(2006): request_location_fix_callback: GPS session is ongoing.
08-25 10:02:57.009: ERROR/GPS(2006): gen_timer_add_locked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您重新启动手机时,所有非持久数据将像变量一样被清除。如果您想保存您的位置,那么您应该使用database/sharedPreferences。
另外,您可能会获取
null
位置。因此您应该继续检查以进行处理。编辑
您可以使用 Timer 类。
尝试这样:
以下代码将在 20 秒后执行。
when you restart your phone then all the non-persistent data will be cleared like variable.If you want to save your location then you should use database/sharedPreferences.
Also,you can get
null
location.So you should keep checking to handle.Edited
You can use Timer class.
Try like this:
Following code will be executed after 20 sec.
查看深入了解位置几乎了解如何获取位置的所有信息。
Have a look at A Deep Dive Into Location to know pretty much all about how to get a location.
我设法解决了这个问题。我创建了没有按钮的 AlertDialog 并启动了 requestLocationUpdates。在 locationListener 中,当位置更改时,我取消了 AlertDialog,这解决了我的问题:D
谢谢杰纳尔和托斯顿......
I managed to solve the problem. I created AlertDialog with no buttons and started requestLocationUpdates. In locationListener, when location changed i canceled AlertDialog and that solved my problem :D
THANKS jainal and Torsten....