I am new to android, carry it with me.
I have a TimerTask for which I define run () inside the Service. Inside run () I call
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
LOCATION_UPDATES_MIN_TIME_MS, LOCATION_UPDATES_MIN_DISTANCE_M, gpsListener);
and he complains that he cannot create a handler, since I consider it a background thread. How to solve it?
Edit: code snippet
locationTask = new TimerTask() {
@Override
public void run() {
Log.d(Commands.TAG, "Running location Task");
myLocationProvider = new MyLocationProvider(locationManager, handler, MyService.this);
myLocationProvider.start();
myLocationProvider.stop();
}
};
and then his schedule as follows:
locationTimer = new Timer();
locationTimer.schedule(locationTask, 10000, cmds.getAlertInterval()*60);
and when .start is called, requestLocationUpdates () fails
source
share