开发者

stop async task after 60 second

i want to stop async task after 60 second

i know there is a method get(t开发者_JAVA技巧ime , timeunit) which i should be using in doInBackground but i dont know how to check if the time out has reached or not please provide that sample one line code .

Thanks


If I understand your question correctly, you already know how to abandon the task after n seconds, but you need to know IF it was abandoned?

According to AsyncTask docs it'll throw a TimeoutException.

Do something like:

try {
    //your AsyncTask code
} catch(TimeoutException ex) {
    //your timeout code
}


you can use a TimerTask to which you can start in the doInBackround() with the schedule for 60 seconds. in the run() of the TimerTask just call the stop for the async task.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜