i have created timer in service so i get error how to slove this in android -


i have created 1 service , added in manifest. when use timer call service periodically , in timer have used location manager location of user contin. there error that:

05-11 11:57:17.574: error/androidruntime(3305): java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare()

tell me problem in code.

code here

package com.collabera.labs.sai;  import java.util.timer; import java.util.timertask;  import android.app.service; import android.content.context; import android.content.intent; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.os.ibinder; import android.util.log; import android.widget.toast;  public class simpleservice extends service {     timer mytimer;  @override public ibinder onbind(intent arg0) {     // todo auto-generated method stub     return null; }  @override public void oncreate() {     super.oncreate();     toast.maketext(this,"service created ...", toast.length_long).show();     mytimer = new timer();     mytimer.schedule(new timertask() {          @override         public void run() {             // todo auto-generated method stub             //getdata();             locationmanager mlocmanager = (locationmanager) getsystemservice(context.location_service);             locationlistener mloclistener = new mylocationlistener();             mlocmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0,                     mloclistener);          }     },0,1000);  }  @override public void ondestroy() {     super.ondestroy();     toast.maketext(this, "service destroyed ...", toast.length_long).show(); } public void getdata() {  } public class mylocationlistener implements locationlistener {     @override     public void onlocationchanged(location loc) {         loc.getlatitude();         loc.getlongitude();         string text = "my current location is: " + "latitude = "                 + loc.getlatitude() + "longitude = " + loc.getlongitude();         /*toast.maketext(getapplicationcontext(), text, toast.length_short)                 .show();*/         log.d("tag", "starting..");     }      @override     public void onproviderdisabled(string provider) {         /*toast.maketext(getapplicationcontext(), "gps disabled",                 toast.length_short).show();*/     }      @override     public void onproviderenabled(string provider) {         /*toast.maketext(getapplicationcontext(), "gps enabled",                 toast.length_short).show();*/     }      @override     public void onstatuschanged(string provider, int status, bundle extras) {     } }/* end of class mylocationlistener */ } 

toast.maketext(this, "service destroyed ...", toast.length_long).show(); 

you can't modify ui non-ui thread. services never executed on ui thread. log instead of making toast.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -