Handler is part of the Android system's framework for managing threads. A Handler object receives messages and runs code to handle the messages. Normally, you create a Handler for a new thread, but you can also create a Handler that's connected to an existing thread. When you connect a Handler to your UI thread, the code that handles messages runs on the UI thread. This way results of background work can be moved to UI elements such as bitmaps.
Questions tagged [android-handlerthread]
79 questions
2
votes
1 answer
Is it bad to have many HandlerThreads alive, doing nothing, just waiting?
I use Handler in conjunction with HandlerThread all over in my Android project. I use most of them in Services. There, my Handlers backed by an individual HandlerThread with low priority get created in onCreated() and stopped in onDestroy().
Many of…

OneWorld
- 17,512
- 21
- 86
- 136
2
votes
3 answers
Synchronization object between two HandlerThreads in Android
I want to synchronize an object model in Android between two handler thread object. One object is "observable" and second is an observer. Both of them works in own threads infinitely. An observer register to observable by "registerListener" method…

piotrpawlowski
- 767
- 2
- 9
- 19
2
votes
1 answer
getLooper() returns null after started HandlerThread
I have an class extends HandlerThread, it looks like this:
public class MyHandlerThread extends HandlerThread {
private Object lock;
//constructor
public MyHandlerThread() {
super(“MyHandlerThread”);
lock = new Object();
}
…

user842225
- 5,445
- 15
- 69
- 119
2
votes
1 answer
Android: What happens after a HandlerThread is started?
HandlerThread thread = new HandlerThread("DownloadService");
thread.start();
Is the looper associated with the thread waiting for a message to arrive in the message queue just after thread.start() returns? If so, then all I need to do is to…

Amit
- 519
- 1
- 5
- 20
2
votes
1 answer
Geolocation request made in background thread freezes the main thread
I have the following working flow of my application: main activity has a button which starts the second activity after the click. In the second activity there is a TextView which shows the city which located in the specified geopoint. To find this…

aga
- 27,954
- 13
- 86
- 121
2
votes
2 answers
HandlerThread.getLooper() blocks indefinitely
I am trying to learn how to run MediaPlayer in its own thread, using HandlerThread. But I'm failing at the very first step. I have spent 2 days painfully trying to understand threads in Java/Android and really need some help. (I have read countless…

Jodes
- 14,118
- 26
- 97
- 156
1
vote
1 answer
How to stop a ServiceHandler in Android, which uses HandlerThread?
I am trying to read sensor data from my phone. I have started a service, which created a HandlerThread to collect sensor data. The thread registers the sensor for a short while and unregisters it. When I stop the service, however, the thread keeps…

Brotchu
- 115
- 1
- 8
1
vote
1 answer
Can adding anonymous runnables in the queue of a Handler thread cause a memory leak?
Will this code cause a memory leak if it is present in the Activity VS ViewModel component?
handlerThread = new HandlerThread("myHandlerThread");
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
…

Mena
- 3,019
- 1
- 25
- 54
1
vote
1 answer
How to resolve ANR problem occured in SensorEventListener operating separete thread?
I'm noob at Java Android Programming(actually I'm noob at overall computer programming). I intended to make SensorEventListener of Accelometer sensor in a thread separate from main thread at Service. onSencorChanged method works well in separate…

PGD
- 13
- 3
1
vote
2 answers
android - cancel runnable that already start running
I have a long process in the background to do. So onCreate, I post a runnable in my handler from handlerThread but I have a button that allows users to cancel it. It's possible to stop a Runnable after it starts?
@Override
protected void…

ola
- 35
- 3
1
vote
0 answers
Code execution interrupted a few times in a HandlerThread
I have a strange problem. There is code execute interrupted in a handlerthread. The enviroment is an Android system's car machine. In the last year's test time of this project, I have encountered the problem more than five times.But see the log,I…

Bruce
- 11
- 1
1
vote
0 answers
java.lang.OutOfMemoryError: Could not allocate JNI Env at handlerthread.start()
My application started to crash at handlerthread.start() line. Following is the full stack traces.
Caused by java.lang.OutOfMemoryError: Could not allocate JNI Env
at java.lang.Thread.nativeCreate(Thread.java)
at…

Hilal
- 902
- 2
- 22
- 47
1
vote
1 answer
Android - When to use HandlerThread/Thread/ThreadPool/IntentService?
I know how to use each one of HandlerThread/Thread/ThreadPool/IntentService,
But I'm really don't know which one I need to pick to use for background task.
Somebody have some tips when to use each one?

I.Mac
- 289
- 3
- 17
1
vote
3 answers
Matter of Handlers execution in a sequence
I took this snipet from a site explaining handler in Android (a threading thing).
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
…

Plain_Dude_Sleeping_Alone
- 1,849
- 2
- 23
- 49
1
vote
1 answer
condition signal from handler postDelayed?
I'm very new to Android programming so pls excuse my ignorance...
I'm trying to do simple Android app:
User presses a button, starts postDelayed job and then waits on conditional var
after timeout the postDelayer job should signal
private final…

V0idd
- 95
- 1
- 7