Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Stop asyncTask in background

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 329
    Comment on it

    We know that asyncTask class has four override methods and three methods runs in main ui thread but one method doInBackground runs in background thread. In case if we want to stop this background service based on same condition then we can use this logic to stop background service in between of progress like this :

     protected Object doInBackground(Object... x) {
    while (/* condition */) {
      // work...
      if (isCancelled()) break;
    }
    return null;}
    

    hope this will help you to stop any service.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: