I'm wondering when should I use handler.post(runnable);
and when should I use
new Thread(runnable).start();
It is mentioned in developers documentation for Handler:
Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached.
Does this mean if I write in the onCreate()
of Activity
class:
Handler handler = new Handler();
handler.post(runnable);
then runnable will be called in a separate thread or in the Activity's thread?
new Thread(runnable).start()
, you can run out of VM Stack Memory Size. You want to useExecutors
and store a reference to that (don't create a new executor per each call that would go to a background thread) – Wellman