Android RequestLocationUpdate无法从线程工作

Android RequestLocationUpdate无法从线程工作,android,multithreading,location,Android,Multithreading,Location,您好,我正在尝试从UI线程以外的线程请求LocationUpdate,我在下面一行中得到一个RuntimeExeption: // request location updates using Cellular lm.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 然后阅读文档,它说它抛出: IllegalArgumentException

您好,我正在尝试从UI线程以外的线程请求LocationUpdate,我在下面一行中得到一个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  
所以我的线程似乎没有活套,但问题是我不知道它们所说的“活套”是什么意思。提前谢谢

将您的
run()
代码更改为

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

    // The rest of your code

    Looper.loop();
}
你可以试试这个:

lm.requestLocationUpdates(
    LocationManager.NETWORK_PROVIDER,
    0,
    0,
    locationListener,
    Looper.myLooper()
);

我应该在整个run()方法中使用Looper,还是只围绕该特定行?谢谢将其放在整个run()方法上,如我上面所述。应该没什么区别。我知道这是史前的,但添加Looper.loop();他为我做了这件事。