Skip to content Skip to sidebar Skip to footer

Set Timeout Function With Asynctask [android]

In my case, I would like to get the button pressed and get process with the timeout. When button clicked then it will verify the accNo with web services, if the verification (Progr

Solution 1:

get() method will block the UI thread and I guess you don't want this.

You should implement cancel mechanics in doInBackground and call AsyncTask.cancel() by timeout [like that](https://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long))

finalHandlerhandler=newHandler();
    handler.postDelayed(newRunnable() {
      @Overridepublicvoidrun() {
        AsyncTask.cancel();
      }
    }, 1);

Be aware there are many gotchas with AsyncTask, check my article.

Post a Comment for "Set Timeout Function With Asynctask [android]"