java - Changing url/ip when asynctask is running repeatedly -
i have call getxmltask service , repeatedly call every 1 seconds data ip address (myip).
myservice.java
public class myservice extends service { public int onstartcommand(intent intent, int flags, int startid) { if (globalfunctions.isinternetavailable(myservice.this) || globalfunctions.iswifi(myservice.this)) { mytimertask mytask = new mytimertask(); timer mytimer = new timer(); mytimer.schedule(mytask, 1000, 1000); } else { toast.maketext(myservice.this, "no internet connection", 1000).show(); } return service.start_sticky; } class mytimertask extends timertask { public void run() { getxmltask task = new getxmltask(); task.execute(new string[] { myip }); } } }
asynctask use in getxmltask.java.
public class getxmltask extends asynctask<string, void, string> { @override protected string doinbackground(string... urls) { try { string output = null; (string url : urls) { output = getoutputfromurl(url); } return output; } catch (exception e) { return null; } } }
and when apps running, have change ip address, "urls" still showing previous ip address (see data eclipse debug mode) , "urls" updated after quite long time.
may know should urls in asynctask can directly take newest ip address without long delay.
thank much
updated 24/4/2014:
i have make changes doinbackground code, data received ip address still not updated data.
protected string doinbackground(string... urls) { try { string output = null; string[] newurl = {globalvariables.global_url + "/status.xml"}; (string url : newurl) { output = getoutputfromurl(url); } return output; } catch (exception e) { return null; } }
any idea? thank you
updated 25/4/2014:
i have debug code , notice when ip address changed, asynctask seem freeze quite long time. have put break point in doinbackground, , doesn't go in. idea? thank you
the loop in doinbackground processing urls sequentially. may need check change in ip inside loop , if ip has changed needful (for example updating urls accordingly).
Comments
Post a Comment