I think it is common to load data and refresh it after some time as the data may change. My question is about how to load it periodly and how to retry the load action when load failed .
I tried to use AsyncTask to get this job done, but my code is ugly, I want to know if there are some elegant solution to deal with this.
I have some concerns:
Sounds complex, any good code example for this requirements?
Simple follow the following steps
Declare a timer task and schedule with Timer by method scheduleAtFixedRate(TimerTask task, long delay, long period)
private class MyTask extends TimerTask { public void run(){ // Call to your async task by execute } }
declare a Handler
When the Async Task done either in getting image or fail to do that.. send an empty message on the instance of the handler object
in handler cancle the async task
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.