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
3
votes
4 answers

Android Splash Screen with network load and minimum splash display time

I'm currently using below structure in my splash screen activities in order to show it for specified time period: new Handler().postDelayed(new Runnable() { @Override public void run() { startMainActivity(); } …
VSB
  • 9,825
  • 16
  • 72
  • 145
3
votes
0 answers

Handler still alive after removeCallbacksAndMessages, removeCallbacks and removeMessages

I have a background thread managing bluetooth data. In my first activity I have a handler, when some data is received a second activity is started: private Handler mHandler1 = new Handler() { @Override public void handleMessage(Message…
Madbyte
  • 95
  • 9
3
votes
3 answers

does service or handler go to sleep too when device's lcd goes off?

I want to develop a sleep tracking app that should work even when device's screen gets off. I'm curious about whether Service or Handler go to sleep when device screen is off. I learned the life-cycle of activity, so I don't think a Handler would…
3
votes
1 answer

Scheduling recursive handlers from an IntentService for retrying http calls

I am trying to implement exponential backoff for retrying failed http calls by scheduling a thread with handler.postDelayed(...) every time my request fail. The problem is that I am doing this from an IntentService which dies after scheduling the…
3
votes
1 answer

handler.removeCallbacksAndMessages not working

My app has a service that registers ScreenStateReceiver which creates a handler when the screen is on and removes it when the screen is off. My problem is that handler.removeCallbacksAndMessages doesn't work when the screen is off. I know that…
idk
  • 57
  • 1
  • 5
3
votes
3 answers

Nutiteq: ViewLabel: Delayed Button execution

I am trying to create a nutiteq ViewLabel with an custom view containing three Buttons. My code and the problem are very similar to this post nutiteq: Button resp. clickable Views not working in Custom ViewLabel. With the provided answer of the…
pekayde
  • 118
  • 10
3
votes
3 answers

Android: can you access AsyncTask class members in DoInBackground?

Is it safe to run a method of an AsyncTask class member inside the DoInBackground? or do you need to use a handler? private class MyAsyncTask extends AsyncTask { Object mObjA = null: private MyAsyncTask(Object objA) { …
Daniele B
  • 19,801
  • 29
  • 115
  • 173
3
votes
3 answers

Handler and Thread inside Service keeps running, while the Service seems to have stopped

I have a Service that uses Handler and Thread to run some code every 5 seconds. When I call stopSelf() the service seems to have stopped, because from the device Setting -> Apps -> Running it doesn't show there. But the code inside the thread keeps…
Mohammed Ali
  • 2,758
  • 5
  • 23
  • 41
3
votes
1 answer

Communicating with the UI Thread Android: User Inactivity

I have a Android application that verifies the user inactivity through a Handler. But I would like know if my Handler implementation is the best solution in my case. The code: public abstract class UserInteractionControlActivity extends Activity { …
falvojr
  • 3,060
  • 4
  • 31
  • 54
3
votes
1 answer

How to call getLooper() on main Thread?

In Android, Main Thread & HandlerThread has Looper & MessageQueue by default. I can call getLooper() on handlerThread object, but why not on main Thread ? HandlerThread ht = new HandlerThread(); Looper htLooper = ht.getLooper(); // Works…
Ashok Bijoy Debnath
  • 1,493
  • 1
  • 17
  • 27
3
votes
2 answers

Is a Handler a Thread or not, and what is the role of a Looper with Handlers and Threads?

Is a Handler a Thread or not? If yes, how can we update the UI from this Handler(thread)? If we use the Looper concept, it may be possible. In this case, does it apply to any threads? I am very much confused about these Threads, Handlers and…
3
votes
0 answers

AsyncQueryHandler doesn't executes the startQuery()

I'm struggling with the following weird bug and could find out whether its source is in my code or in the Android-19 code. I'm trying to query the content provider async using AsyncQueryHandler, but its onQueryComplete() never got called. When I…
Nativ
  • 3,092
  • 6
  • 38
  • 69
3
votes
1 answer

Handler.handleMessage is not called in test, but is called in the app

I have a service that runs in a separate process. The service spawns a new thread in onCreate() method. This thread sends messages back to the service. If I start the app manually everything works fine - messages are received by the Handler in my…
bmv2143
  • 734
  • 1
  • 8
  • 17
3
votes
3 answers

Runnable is executed long time after postDelayed's delay

At some point I want my Service to execute something after 2 seconds. So - I had prepared a designated Handler: private Handler handler; ... HandlerThread thread = new HandlerThread("LNT"); thread.start(); handler = new…
DuduArbel
  • 1,100
  • 1
  • 12
  • 25
3
votes
3 answers

How to set up a timer for an android game ?

I want to programm a game for Android. Play principle: The user should have a short time to choose the correct answer. My problem is the combination between the input (choosing the answer) and the time (countdown). I tried to run a thread, but the…
Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68