您好,我正在尝试从 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/