Saturday, 15 May 2010

java - animateCamera, IllegalStateException: Not on the main thread -



java - animateCamera, IllegalStateException: Not on the main thread -

i have separate map class in have written logic related map activities strict requirement maintain both map related things separate. main app activity calling function this:

timer t = new timer(); t.scheduleatfixedrate(new timertask() { @override public void run() { if (mapobj.islocationclientconnected) location currentlocation = mapobj.gotocurrentlocation(); } }, 0, refreshuserlocationinterval);

and in map class have:

public location gotocurrentlocation() { currentlocation = mlocationclient.getlastlocation(); latlng ll = new latlng(currentlocation.getlatitude(), currentlocation.getlongitude()); cameraupdate cupdate = cameraupdatefactory.newlatlngzoom(ll, defaultzoom); gmap.animatecamera(cupdate); homecoming currentlocation; }

but error:

06-22 19:56:30.900: e/androidruntime(11413): fatal exception: timer-0 06-22 19:56:30.900: e/androidruntime(11413): java.lang.illegalstateexception: not on main thread 06-22 19:56:30.900: e/androidruntime(11413): @ kbh.b(unknown source) 06-22 19:56:30.900: e/androidruntime(11413): @ lzd.b(unknown source) 06-22 19:56:30.900: e/androidruntime(11413): @ mbi.b(unknown source) 06-22 19:56:30.900: e/androidruntime(11413): @ fms.ontransact(sourcefile:92) 06-22 19:56:30.900: e/androidruntime(11413): @ android.os.binder.transact(binder.java:310) 06-22 19:56:30.900: e/androidruntime(11413): @ com.google.android.gms.maps.internal.igooglemapdelegate$a$a.animatecamera(unknown source) 06-22 19:56:30.900: e/androidruntime(11413): @ com.google.android.gms.maps.googlemap.animatecamera(unknown source) 06-22 19:56:30.900: e/androidruntime(11413): @ com.mapworlds.mapworlds.mapclass.gotocurrentlocation(mapclass.java:176)

i want maintain animatecamera in same function within map class. have main context main app available variable in class, can utilize , create work?

in fact, animatecamera modifies ui component (the map), must done on ui thread.

edit

you can :

timer t = new timer(); t.scheduleatfixedrate(new timertask() { @override public void run() { runonuithread(new runnable() { public void run() { //update ui if (mapobj.islocationclientconnected) location currentlocation = mapobj.gotocurrentlocation(); } }); } }, 0, refreshuserlocationinterval);

java android google-maps

No comments:

Post a Comment