If I call an asyncTask from a thread will the onPostExecute() execute on the thread or the calling activity

Zapnologica

I have my main application running. I then start a new thread.

In this thread i call an asyncTask.

Will its

protected void onPostExecute(Long result) {
     showDialog("Downloaded " + result + " bytes");
 }

method execute on the thread or on the application calling the thread?

Steve Benett

The docs are very specific about this point:

  • The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN.
  • The task instance must be created on the UI thread.
  • execute(Params...) must be invoked on the UI thread.

This is because the AsyncTask internally uses a Handler to do the communication with the Thread which called new and execute() on it. If this Thread is the UI-Thread, there is no problem. Otherwise the calling Thread has to be a Looper to be able to link UI changing operations and event handling with the UI-Thread.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

If I call an asyncTask from a thread will the onPostExecute() execute on the thread or the calling activity

From Dev

Does onPreExecute() and onPostExecute() execute on the UI thread or on the thread from which the AsyncTask has been started?

From Dev

Does onPreExecute() and onPostExecute() execute on the UI thread or on the thread from which the AsyncTask has been started?

From Dev

Call activity in method onPostExecute from asynctask class

From Dev

Execute Python function in Main thread from call in Dummy thread

From Dev

AsyncTask not calling onProgressUpdate,onPostExecute

From Dev

Calling method of activity from asynctask

From Dev

IntentService class not running AsyncTask on main ui thread. Method execute must be called from the main thread, currently inferred thread is worker

From Dev

AsyncTask onPostExecute() is not called from Fragment class but works in Activity class

From Dev

How to call another activity from drawing thread (SurfaceView)

From Dev

Android: Can't call new activity from class that extends Thread

From Dev

Thread.Sleep() in C#: Does it sleep the thread the object was instantiated in, or the thread i am calling the method from?

From Dev

Should I call super.onPostExecute(result) in Android AsyncTask?

From Dev

Should I call super.onPostExecute(result) in Android AsyncTask?

From Dev

How to call notifyDataSetChanged() from AsyncTask onPostExecute() in another class

From Dev

Call onResume() method from Asynctask's onPostExecute() Method

From Dev

Calling a thread inside a thread gives me errors, works fine if I just call the function

From Dev

how to call getWritableDatabase() from a different thread or intent service, App crashing on calling it in the main thread

From Dev

Starting activity from a separate thread?

From Dev

Pass data from thread to activity

From Dev

Calling methods from a running Thread

From Dev

Calling requestLayout from a separate thread

From Dev

Android: call main activity method from Async onPostExecute method

From Dev

call function of main thread from secondary thread

From Dev

Call function in main thread from another thread?

From Dev

Call AsyncTask in the parent activity from fragment

From Dev

Call different activity method from AsyncTask

From Dev

Call AsyncTask in the parent activity from fragment

From Dev

Call viewpager's asynctask from above activity

Related Related

  1. 1

    If I call an asyncTask from a thread will the onPostExecute() execute on the thread or the calling activity

  2. 2

    Does onPreExecute() and onPostExecute() execute on the UI thread or on the thread from which the AsyncTask has been started?

  3. 3

    Does onPreExecute() and onPostExecute() execute on the UI thread or on the thread from which the AsyncTask has been started?

  4. 4

    Call activity in method onPostExecute from asynctask class

  5. 5

    Execute Python function in Main thread from call in Dummy thread

  6. 6

    AsyncTask not calling onProgressUpdate,onPostExecute

  7. 7

    Calling method of activity from asynctask

  8. 8

    IntentService class not running AsyncTask on main ui thread. Method execute must be called from the main thread, currently inferred thread is worker

  9. 9

    AsyncTask onPostExecute() is not called from Fragment class but works in Activity class

  10. 10

    How to call another activity from drawing thread (SurfaceView)

  11. 11

    Android: Can't call new activity from class that extends Thread

  12. 12

    Thread.Sleep() in C#: Does it sleep the thread the object was instantiated in, or the thread i am calling the method from?

  13. 13

    Should I call super.onPostExecute(result) in Android AsyncTask?

  14. 14

    Should I call super.onPostExecute(result) in Android AsyncTask?

  15. 15

    How to call notifyDataSetChanged() from AsyncTask onPostExecute() in another class

  16. 16

    Call onResume() method from Asynctask's onPostExecute() Method

  17. 17

    Calling a thread inside a thread gives me errors, works fine if I just call the function

  18. 18

    how to call getWritableDatabase() from a different thread or intent service, App crashing on calling it in the main thread

  19. 19

    Starting activity from a separate thread?

  20. 20

    Pass data from thread to activity

  21. 21

    Calling methods from a running Thread

  22. 22

    Calling requestLayout from a separate thread

  23. 23

    Android: call main activity method from Async onPostExecute method

  24. 24

    call function of main thread from secondary thread

  25. 25

    Call function in main thread from another thread?

  26. 26

    Call AsyncTask in the parent activity from fragment

  27. 27

    Call different activity method from AsyncTask

  28. 28

    Call AsyncTask in the parent activity from fragment

  29. 29

    Call viewpager's asynctask from above activity

HotTag

Archive