android - How to execute a static method inside a handler -
this code current location , address , send url using post method
final handler myhandler = new handler(); runnableforadd = new runnable() { public void run() { gps = new gpstracker(dashboard.this); // check if gps enabled if(gps.cangetlocation()){ double latitude = gps.getlatitude(); double longitude = gps.getlongitude(); geocoder = new geocoder(dashboard.this, locale.getdefault()); seek { list<address> addresses = geocoder.getfromlocation(latitude, longitude, 1); if(addresses != null) { address returnedaddress = addresses.get(0); strreturnedaddress = new stringbuilder(""); for(int i=0; i<returnedaddress.getmaxaddresslineindex(); i++) { strreturnedaddress.append(returnedaddress.getaddressline(i)).append("\n"); } arraylist<namevaluepair> postparameters = new arraylist<namevaluepair>(); postparameters.add(new basicnamevaluepair("uid", uid)); postparameters.add(new basicnamevaluepair("location",strreturnedaddress.tostring())); postparameters.add(new basicnamevaluepair("lat", string.valueof(latitude))); postparameters.add(new basicnamevaluepair("lng", string.valueof(longitude))); postparameters.add(new basicnamevaluepair("did", dsid)); customhttpclient.executehttppost("http://www.cjcld.org/dvts1/mobile/updatesperiod.php", postparameters); toast.maketext(getapplicationcontext(), "your location - \nlat: " + latitude + "\nlong: " + longitude+"\n"+strreturnedaddress.tostring(), toast.length_long).show(); myhandler.postdelayed(runnableforadd, 10000); }else{ toast.maketext(getapplicationcontext(), "your location - \nlat: " + latitude + "\nlong: " + longitude+"\nno address found", toast.length_long).show(); myhandler.postdelayed(runnableforadd, 10000); } } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (exception e) { // todo auto-generated grab block e.printstacktrace(); } // \n new line }else{ // can't location // gps or network not enabled // inquire user enable gps/network in settings gps.showsettingsalert(); } } }; myhandler.postdelayed(runnableforadd, 10000);
but part doesn't execute:
arraylist<namevaluepair> postparameters = new arraylist<namevaluepair>(); postparameters.add(new basicnamevaluepair("uid", uid)); postparameters.add(new basicnamevaluepair("location",strreturnedaddress.tostring())); postparameters.add(new basicnamevaluepair("lat", string.valueof(latitude))); postparameters.add(new basicnamevaluepair("lng", string.valueof(longitude))); postparameters.add(new basicnamevaluepair("did", dsid)); customhttpclient.executehttppost("http://www.cjcld.org/dvts1/mobile/updatesperiod.php", postparameters);
i don't errors, doesn't execute.
this logcat warning.
02-13 21:07:57.320: w/system.err(24264): java.io.ioexception: unable parse response server 02-13 21:07:57.330: w/system.err(24264):at android.location.geocoder.getfromlocation(geocoder.java:136) 02-13 21:07:57.330: w/system.err(24264): @ com.example.deliveryvantrackingsystem.dashboard$1.run(dashboard.java:85) 02-13 21:07:57.330: w/system.err(24264):at android.os.handler.handlecallback(handler.java:605) 02-13 21:07:57.330: w/system.err(24264): @ android.os.handler.dispatchmessage(handler.java:92) 02-13 21:07:57.330: w/system.err(24264):at android.os.looper.loop(looper.java:137) 02-13 21:07:57.330: w/system.err(24264):at android.app.activitythread.main(activitythread.java:4476) 02-13 21:07:57.330: w/system.err(24264):at java.lang.reflect.method.invokenative(native method) 02-13 21:07:57.330: w/system.err(24264):at java.lang.reflect.method.invoke(method.java:511) 02-13 21:07:57.340: w/system.err(24264):at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:816) 02-13 21:07:57.340: w/system.err(24264):at com.android.internal.os.zygoteinit.main(zygoteinit.java:583) 02-13 21:07:57.340: w/system.err(24264):at dalvik.system.nativestart.main(native method)`
android android-asynctask handler
No comments:
Post a Comment