I have service and a mapActivity.
I wish to update mapview outfrom serivce (draw new oerlays lets say each 15 sec.)
I get error:
can’t create handler inside thread that has not called looper.prepare();
my code:
private void startService() {
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
MyMap map = new MyMap(); // here is where app crashes...}
}
}
You can’t have UI code in a background service. Anything running in a service runs on a background thread rather than on the app’s UI thread, meaning that you cannot make UI changes from there. That’s why you get the error.
If you sit back and think about it, architecturally there is no reason to have UI code in a background service. Drawing the map is a purely foreground operation and ceases to matter as soon as the map activity is dismissed. Hence no need to have background code stick around in a service — all the overlay code belongs in the foreground map activity.