Repeat AsyncTask

前端 未结 3 664
情话喂你
情话喂你 2021-01-02 22:10

I have a doubt about the possibility of repeating an AsyncTask in an application for Android. I would like to repeat some operations, the download of a file from a server fo

3条回答
  •  醉话见心
    2021-01-02 22:28

    You cannot reuse the same AsyncTask object as, according to the AsyncTask Docs

    The task can be executed only once (an exception will be thrown if a second execution is attempted.)

    But you can create however many new objects of that class you need inside of a loop. However a better way you be to do the download operation n number of times inside your doInBackground().

    If this doesn't answer your question then please be more specific as to your problem

提交回复
热议问题