0

加速度計データをチェックするAsyncTaskがあります。加速度計がより大きな値を示していることを検出したときはいつでも、GPS記録を開始する必要があります。

private LocationManager mlocManager;
private GPSLocationListener mlocListener;
..
mlocManager = (LocationManager)context.getSystemService(context.LOCATION_SERVICE);
mlocListener = new GPSLocationListener();
..
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 100, mlocListener); 
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 100, mlocListener); 

これを実行するにはどうすればよいですか?私が得るエラーは

error occured while executing doInBackground()
Can't create handler inside thread that has not called Looper.prepare()
4

1 に答える 1

1

AsyncTaskはルーパースレッドで実行されないため、問題が発生します。ハンドラーはルーパースレッドで実行されるため、このようなエラーは発生しません。

于 2012-10-03T09:53:20.103 に答える