Is it possible to implement a loop in AsyncTask, which will be repeated either a certain number of times, or until the moment when the user clicks the "cancel" button and, if so, where should it be registered? In doInBackGround or create a separate method / class for this?

    1 answer 1

    Sure you may. Insert your cycle in AsyncTask.doInBackground() , then where you need to stop, AsyncTask.cancel() and check the AsyncTask.isCancelled() value in your cycle in AsyncTask.doInBackground() and if true - fly out of there in FIG and everything stops.

    • Fly through the break? - alreadyexist 2:53 pm
    • one
      Barmel wrote so that you can break the MOSH =), you probably enough by your condition to call AsyncTask.cancel () and that's it. Those. the user on the form presses CANCEL - you call AsyncTask.cancel (), the AsyncTask.isCancelled () method will return a job if the AsynTTask is completed before it has completed its work. - Gorets
    • @Gorets, @alreadyexist - well, someone understood, but someone does not ... Do I even need to write the code with catching all possible cases, exceptions? I painted the general scheme, and then themselves - this is your bread, work it out! - Barmaley