0

If I try to execute an asynce task twice I get an illegal state exception.

07-29 18:14:21.290: ERROR/AndroidRuntime(9080): FATAL EXCEPTION: main
07-29 18:14:21.290: ERROR/AndroidRuntime(9080): java.lang.IllegalStateException: Cannot execute task: the task has already been executed (a task can be executed only once)
07-29 18:14:21.290: ERROR/AndroidRuntime(9080):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:541)
07-29 18:14:21.290: ERROR/AndroidRuntime(9080):     at android.os.AsyncTask.execute(AsyncTask.java:499)

I can overcome it by creating another object of the async task. But this begs a question- Why can't I execute an async task twice? Is it because it the async task is like a thread? This also got me wondering why can't I run a thread twice? Why was the JAVA framework made in this manner?

Vaibhav Sharma
  • 2,293
  • 1
  • 17
  • 24
  • [Have a look](http://stackoverflow.com/q/1215548/681929) – nobalG Feb 19 '16 at 07:32
  • @nobalG Thanks for the answer. But I still don't understand why was it made in such manner. I understand that we can't start a thread since it was already started but why can't I reuse it when it had finished its execution? – Vaibhav Sharma Feb 19 '16 at 07:37
  • 1
    [Read this thread](http://stackoverflow.com/q/4034201/681929) , these tales are deep (upto OS level) – nobalG Feb 19 '16 at 07:40
  • @nobalG Thanks to pointing me to the right direction. – Vaibhav Sharma Feb 19 '16 at 07:45

0 Answers0