Questions tagged [android-handler]

A Handler allows you to send and process `Message` and Runnable objects associated with a thread's `MessageQueue`. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

848 questions
15
votes
1 answer

Android postDelayed vs Coroutines delay

I saw this example and I'm wondering is there any objective reason to implement this using Coroutines delay instead of Android Handler postDelayed? In case the link dies the code from example is below: val watcher = object :TextWatcher{ private…
Spidey
  • 894
  • 1
  • 13
  • 29
14
votes
2 answers

Why use a Messenger rather than passing the reference to a Handler?

I have a main activity and bound service. The bound service receives a command from the network, which triggers a Message to be sent to a Handler in the main activity. I got everything to work by passing the Handler's reference to the service. And…
Rich
  • 785
  • 1
  • 9
  • 22
14
votes
1 answer

Android: Why do Handlers post a runnable?

Can someone explain why Handlers post a runnable? Does overriding handleMessage and sending a message do the same thing? I've written some untested code to show how I think these two ways would be implemented. Please correct me if I'm wrong in my…
Rich
  • 785
  • 1
  • 9
  • 22
14
votes
4 answers

Implementing AsyncQueryHandler

I am trying to implement AsyncQueryHandler because I am experiencing the same exact problem in this link but I dont see any example or anything about implementing it. I tried doing AsyncQueryHandler handler = new…
tyczj
  • 71,600
  • 54
  • 194
  • 296
12
votes
2 answers

Android AsyncTask vs Thread + Handler vs rxjava

I know this is the question which was asked many many times. However there is something I never found an answer for. So hopefully someone can shed me some light. We all know that AsyncTask and Thread are options for executing background tasks to…
H.Nguyen
  • 1,621
  • 5
  • 19
  • 31
12
votes
3 answers

Handler.postDelayed(Runnable) vs CountdownTimer

Sometimes we need to delay a code before it runs. This is doable by the Handler.postDelayed(Runnable) or CountdownTimer. Which one is better in terms of performance? See the sample code below Handler new Handler().postDelayed(new…
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
11
votes
2 answers

sending message to a Handler on a dead thread Google Admob Rewarded video

I got this stacktrace while I came back to my activity from Google Admob's rewarded video screen after completing whole video. Its just warning, not crash. onRewardedVideoAdClosed() method is called after watching video, but onRewarded() does not…
Palak Darji
  • 1,084
  • 18
  • 28
11
votes
3 answers

Android Handler for repeated task - will it overlap ? Timer-task VS handler VS alarm-manager

I'm trying to build an Android app which will repeatedly run some process every 10 mins. As I found out Handlers are more reliable than timers or scheduling. So I'm going to develop my app using the Handlers using the given below codes. I'm little…
kuma DK
  • 1,812
  • 1
  • 18
  • 36
11
votes
4 answers

Android: How to use a Handler handleMessage and access the reference to the MainActivity

I have a service which receives a command from the Internet and launches a background thread. This thread is passed a handler from the service (the service is bounded and passed the handler) and sends a message to the handler to take a picture. I'm…
Rich
  • 785
  • 1
  • 9
  • 22
11
votes
5 answers

Should I manually close HandlerThreads created by my application when destroying the activity?

My app is composed of a single Activity. In this activity, I'm creating multiple HandlerThreads which run in a loop to do socket blocking operations. Currently I post a quit message to everyone of these HandlerThreads during my…
Daniel L.
  • 5,060
  • 10
  • 36
  • 59
10
votes
6 answers

handler.postDelayed is not working in onHandleIntent method of IntentService

final Handler handler = new Handler(); LOG.d("delay"); handler.postDelayed(new Runnable() { @Override public void run() { LOG.d("notify!"); //calling some methods here } }, 2000); The "delay" does shows in the log, but not…
10
votes
1 answer

GIF type animation for marker in google map api ANDROID

I want to achieve a marker animation such as GIF animation. I got two images which should be blinking simultaneously. I found nothing which can acheive this in android. I am trying to do is , creating a handler which run every 1 second , and I am…
10
votes
6 answers

Missing the android.os.handler object from Android Studio

I'm attempting to create a Handler thread in my application however Android Studio marks my text as red and will only attempt to import the java.util version of a handler and not the Android SDK version. When attempting to import manually I'm able…
b1kjsh
  • 1,109
  • 2
  • 9
  • 21
8
votes
2 answers

What happens to this thread runnable at the end once it is completed?

I have this thread which downloads a few images from the server. So once it downloads the images I call the handler and carry on UI updation. So since stop() for thread is deprecated I am not able to use it. I have two questions here. What happens…
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
8
votes
3 answers

Mutation of a Bundle object

I'm working with the legacy code and I found an inconsistent behavior in this function: @Override public void openFragment(final Class fragmentClass, final boolean addToBackStack, …
Maxim G
  • 1,479
  • 1
  • 15
  • 23
1 2
3
56 57