Stop an asynchronous task after 60 seconds

I want to stop the asynchronous task after 60 seconds

I know that there is a get (time, timeunit) method that I have to use in doInBackground but I don’t know how to check if the timeout has reached or not, please provide an example of one line code.

thank

+1
source share
2 answers

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

According to AsyncTask docs , it throws a TimeoutException.

Do something like:

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

TimerTask, doInBackround() 60 . run() TimerTask async.

+4

All Articles