【发布时间】:2011-10-21 11:40:35
【问题描述】:
我有以下代码:
public class DumpLocationLog extends Thread {
LocationManager lm;
LocationHelper loc;
public void onCreate() {
loc = new LocationHelper();
lm = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);
}
public void run() {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, loc);
}
}
我希望它从远程服务运行,但在 lm = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE); 行中我当然会收到 NullPointerException 错误,因为 context 为空。
我怎样才能在这里获得上下文? getBaseContext() 或 getApplicationContext() 不起作用。
【问题讨论】:
标签: android multithreading service location android-context