30秒ごとにループできるようにしたい次のコードがあります。
MyLocation myLocation = new MyLocation();
public LocationResult locationResult = new LocationResult() {
@Override
public void gotLocation(final Location location) {
GeoPoint myGeoPoint = new GeoPoint(
(int) (location.getLatitude() * 1000000),
(int) (location.getLongitude() * 1000000));
myMapController.animateTo(myGeoPoint);
myMapController.setZoom(10);
lat = location.getLatitude();
lon = location.getLongitude();
new OverlayTask().execute();
Timer timer;
timer = new Timer();
timer.scheduleAtFixedRate(new MyTimerTask(), 30000, 30000);
}
};
場所を取得すると起動し、OverlayTaskは正常に実行されます。また、メニュー項目に割り当てられたときにも実行され、強制的に実行されます。
ただし、タイマー内でエラーが発生します。
public class MyTimerTask extends TimerTask {
public void run() {
try {
Log.i(">>>>>>>>>>>> Refresh: ", "Success");
new OverlayTask().execute();
} catch (Exception e) {
Log.e(">>>>>>>>>>>> Error executing MyAsyncTask: ", e.getMessage(), e);
}
}
}
エラーは...です。
MyAsyncTaskの実行エラー:(2573):ビュー階層を作成した元のスレッドのみがそのビューにアクセスできます。