android - requestLocationUpdates 不适用于线程

标签 android multithreading location

您好,我正在尝试从 UI 线程以外的线程请求位置更新,我在以下行中得到一个 RuntimeExeption:

// request location updates using Cellular 
lm.requestLocationUpdates(
    LocationManager.NETWORK_PROVIDER,
    0,
    0,
    locationListener);

然后阅读它说它抛出的文档:

IllegalArgumentException  if provider is null or doesn't exist on this device 
IllegalArgumentException  if listener is null 
RuntimeException  if the calling thread has no Looper 
SecurityException  if no suitable permission is present  

所以好像我的线程没有Looper,但问题是我不知道他们所说的“Looper”是什么意思。提前致谢!

最佳答案

run() 代码更改为

@Override
public void run()
{
    Looper.prepare();

    // The rest of your code

    Looper.loop();
}

关于android - requestLocationUpdates 不适用于线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17916056/

相关文章:

javascript - chrome/angular2 的 window.location.hash 解决方法

android - 为什么我的 Android 应用看起来与英语和西类牙语不同?

android - 修改gradle中的所有flavor .class

java - 使用多线程上传图片到AmasonS3作为存储平台

c# - 如何正确使用实时优先级

python - 单独线程上的扭曲 react 器调用

java - 使用半径搜索附近的物体。谷歌地图

android - 从 XML 资源文件中获取所有字符串资源?

android - 自定义日期选择器

iOS 后台操作 - 是否可以在重要位置更新后执行网络请求?