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
1
vote
0 answers
IntentService is the right choice when we need to start and cancel the process during the execution?
I need to read selected file from external storage in background and then using Universal Image Loader download images, while during the process of reading file from external storage or during the image download process user should have a option to…

I.S
- 1,904
- 2
- 25
- 48
1
vote
1 answer
Are HandlerThreads killed by Android OS automatically?
Suppose I have a HandlerThread in Application class which I use to do some background work. Do I need to stop this thread myself or will it be killed by OS along with Application instance? My code looks something like this.
public class…

Egis
- 5,081
- 5
- 39
- 61
1
vote
1 answer
HandlerThread and Handler: how to use AudioRecord.setRecordPositionUpdateListener?
I'm confused by Handler and HandlerThread classes usage. The reason I'm trying to use them is I want to utilize AudioRecord class and its setRecordPositionUpdateListener method (reference). The methos description says:
Use this method to receive…

Violet Giraffe
- 32,368
- 48
- 194
- 335
1
vote
0 answers
Cost of keeping a HandlerThread alive
In my android application, I'm listening to a couple of system events (which don't get fired quite often) and after each event I post a task which is executed after a short delay (usually 1 minute) in the background.
(after the task completes,…

guy.gc
- 3,359
- 2
- 24
- 39
1
vote
0 answers
Handler thread instance becomes null after creation of the thread
I am getting null pointer exception while quit the thread using its handler thread instance, The instance value becomes null after its creation. If i make the variable as static then I didn't face this problem. Can any one explain me about why the…

Gopal Rao
- 11
- 2
0
votes
1 answer
How to Mock HandlerThread in Android
How can i mock HandlerThreadin Android. I am creating HandlerThread in constructor of a class. I need to mock the HandlerThread to write test case. Here is my code
HandlerThread("TimeoutHandlerThread").apply {
start()
workHandler =…

Abu Yousuf
- 5,729
- 3
- 31
- 50
0
votes
0 answers
Android WebView App :: Errors Name : File error accessing recents directory ; Task 255 failed or timed out ; CancellationException
I have lots of links in my app, I have used the Firebase database for data fetch and data send and also used broadcast receiver.
Most of the time my app is not crashing with these errors, but sometimes it crashed. When it crashed, I opened the…

Plaban Das
- 23
- 6
0
votes
1 answer
UI changes in a thread in android
I'm writing an android application that require me to hold the foreground of an Image Button for a second before changing it again. so I have written the code below (it worked on changing the colors of the text on two buttons in some other project)…

moustafa
- 27
- 5
0
votes
1 answer
Should I use Workmanager for 3 tasks that should run one after the other? - Android studio
I am making an application that should do the following tasks:
image processing in a bitmap
receive String by doing OCR(optical character recognition) in the bitmap that received from task 1
retrieve data from the app's Room's database by searching…

nCoder
- 53
- 5
0
votes
1 answer
Problem with Handler/Looper when use class inherited from HandlerThread, code of handleMessage doesn't run
I have a fragment in my project:
private const val TAG = "PhotoGalleryFragment"
class PhotoGalleryFragment: Fragment() {
private lateinit var photoRecyclerView: RecyclerView
private lateinit var photoGalleryViewModel: PhotoGalleryViewModel
…

Kurowsky
- 154
- 1
- 9
0
votes
1 answer
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 - NFC Handler.handleMessage
I am developing an NFC based android application. I get an arrayIndexOutOfBoundsException length = 0 index = 0 error when sending the object with Message with the Handler class.
Process: com.telpo.tps530_demo, PID:…
0
votes
1 answer
Sending a message from background thread to UI Thread in real time
I am building a metronome in android with sound and a visual blink and of course both things need to be in sync. The problem is that the audio processing happens inside a background thread and as we all very well know "only the thread that created…

JoanaBrew
- 11
- 4
0
votes
0 answers
NullPointerException when invoking Handler.sendEmptyMessageDelayed(int, long)
Saw this crash in Crashlytics after recent app release. It happens 100% in background; 50% in Sony, some in Huawei / Xiaomi, not in Samsung; 79% in Android 10, 19% in Android 8.
Fatal Exception: java.lang.NullPointerException: Attempt to invoke…

C. Leung
- 6,218
- 3
- 20
- 32
0
votes
1 answer
Why does HandlerThread have a run() method, and how should I use it?
I developed several codes using HandlerThread, but so far, it is to some extent difficult to grasp the meaning of the run() method that exists in the Handlerthread class when extended.
HandlerThread class, when extended, some abstract methods are to…

Amrmsmb
- 1
- 27
- 104
- 226
0
votes
0 answers
Where to quit the handler thread that used for realm operations in Android?
I have an android application that I do many realm operations. I wanted to do those stuff on background and to do that I have used handler threads.
I also used handler threads in some of my activities and service classes and I quit() those handler…

Hilal
- 902
- 2
- 22
- 47