Questions tagged [android-handlerthread]

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.

79 questions
36
votes
2 answers

Example communicating with HandlerThread

I want to set up a HandlerThread from the GUI thread. Then some time later, when a button is clicked on the GUI, it runs callHello(), which then send a message to a HelloLogger object residing on the non-GUI thread which asynchronously logs "Hello…
Jodes
  • 14,118
  • 26
  • 97
  • 156
19
votes
6 answers

Why use HandlerThread in Android

In android , Handler can be used to post / handle message, if I don't use a HandlerThread (pass its Looper to Handler), does that mean in this case Handler use MainThread (UI Thread) 's Looper ? What result will get if Handler uses MainThread's…
Daniel
  • 231
  • 1
  • 3
  • 6
10
votes
0 answers

"Long monitor contention with owner" warning

I get this warning message and since I see this message I also started to see the Google Play Services isnt responding popup and it closes my application after some time. I have review similar questions but could not find out the reason. Following…
10
votes
2 answers

HandlerThread vs IntentService

I would like to ask someone to explain me please, what are the main differences between HandlerThread and IntentService, and what are the main use-case scenarios? I understand that HandlerThread contains a Looper, which managing the messageQueue,…
narancs
  • 5,234
  • 4
  • 41
  • 60
6
votes
2 answers

Handler or Launching a Coroutine Job to do something in the MainThread

I've been wondering about whether it is a better approach to use a Handler (Looper.getMainLooper()) or launch a new Coroutine Job to do small things on the Main Thread, like updating a View. Handler: val uiHandler =…
6
votes
1 answer

Completion Handlers in Android

I am an iOS developer who just recently tried Android development. In iOS I use Completion Handlers in my codes. I am wondering if there is an equivalent of it in Android development? Thank you
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
5
votes
3 answers

NullPointerException in HandlerThread

This bug baffled me for hours. I am getting the NullPointerException. The problem is this error is not consistent. It happens when I launch the app, but only occasionally. So I am not sure what is causing it. I apologize for the verbose question…
4
votes
1 answer

Android Handler Not Receiving Message Using HandlerThread

Ia m Using HandlerThread and Handler in my below code, Actually I try to update the data from runnable to Handler callback. In every loop the sendMessage() function Called but I didn't received nothhing in Callback. What I am missing? public class…
appukrb
  • 1,507
  • 4
  • 24
  • 53
4
votes
4 answers

Why does Handler that have set a looper of HandlerThread can interact with UI Objects?

why this code works? @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i("onCreate", Thread.currentThread().toString()); textView =…
3
votes
2 answers

HandlerThread blocks UI android

I am working on a modification of Google's Camera2 API example for Android, found here: https://github.com/googlesamples/android-Camera2Basic I am uploading captured images to Cloudinary, and obviously need to do so in a background thread so the UI…
2
votes
0 answers

handler.post(runnable) run in child thread ,but why it can update ui thread?

this is my code HandlerThread handlerThread = new HandlerThread("test"); handlerThread.start(); Handler handler_test = new Handler(handlerThread.getLooper()); handler_test.post(()->{ Log.d("handlerr_test",…
zadaji
  • 141
  • 6
2
votes
0 answers

Android MessageQueue in Handler sent with unexpected latency

I created an architecture with a process A communicating to another process B through IPC. A runs a sticky service. B runs a sticky service. This A service binds to the B service. When bind succeeds, for requests from A to B, A creates…
2
votes
0 answers

Calling a method in Custom View from a HandlerThread

Hi all I am a beginner in android programming and I am having a little trouble trying to understand how HandlerThread works. Specifically, I am not sure if the method in the custom view class is executed in the background thread (or non-UI thread)…
f00l
  • 21
  • 1
2
votes
0 answers

Android HandlerThread: Handler post doesn't run Runnable sometimes

I am experimenting with HandlerThread on Android, and I can't seem to explain a strange behavior. Here is a class I am using to simply log a message through this unique thread. public class HandlerLogger { MyHandler mHandler; HandlerThread…
Raphael C
  • 2,296
  • 1
  • 22
  • 22
2
votes
2 answers

Why creating HandlerThread for one purpose : to pass it's Looper to a new Handler

I see a lot examples in code were we see the next thing: HandlerThread thread = new HandlerThread("Thread1"); thread.start(); mLoadHandler = new Handler(thread.getLooper()) mLoadHandler.post(new Runnable() { public…
1
2 3 4 5 6