android - Handler executing faster than expected -
i using handler , postdelayed method execute runnable after every 10 seconds. looks executed every second. here code:
final handler handler = new handler(); runnable runnable = new runnable() { @override public void run() { try { if (onetimeexecution && !gcmintentservice.agreedid.equals(null)) { onetimeexecution = false; iterator = jsonavailabeinfos.infoidentification .entryset().iterator(); while (it.hasnext()) { map.entry pairs = (map.entry) it.next(); infoinfo tempinfo = (infoinfo) pairs .getvalue(); if (!tempinfo.getid().equals( gcmintentservice.agreedinfoid)) { marker m = (marker) pairs.getkey(); m.setvisible(false); } else { myinfomarker = (marker) pairs.getkey(); } } } if (!gcmintentservice.agreedinfoid.equals(null)) { getselectedinfolocation infoupdatedlocation = new getselectedinfolocation(); jsonobject jobj = infoupdatedlocation.execute("123").get(); // gcmintentservice.agreedinfoid).get(); double lat=double.parsedouble(jobj.getstring("lat")); double lon=double.parsedouble(jobj.getstring("lon")); log.i("hello", "inside handler executed in every 10 seconds"); latlng loc= new latlng(lat, lon); myinfomarker.setposition(loc); } handler.postdelayed(this, 10000); } catch (exception e) { log.e("infolocationupdate",e.tostring()); } } }; boolean tempflag=true; if(tempflag){ handler.postdelayed(runnable, 10000); tempflag=false; }
fyi last few lines ensure runnable called once , again runnable called recursively. can tell me why getting called every second when should called after 10 seconds?
Comments
Post a Comment