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
6
votes
1 answer

Handler.sendMessageDelayed(msg, delay) not working correctly

I have defined a splashscreen to be shown during loading. But depending on the internet connection it can takes only 600ms to load or sometimes 5000ms. So i defined that the splashscreen is at least shown 3000ms so that the user is not irritated by…
anon
6
votes
0 answers

Find out Leakage issues in Looper or HandlerThread

I have used some Handlers like new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { try{ Messages.onAcknowledgeReceived(); …
Ranjit
  • 5,130
  • 3
  • 30
  • 66
6
votes
6 answers

Handler or a Timer for scheduling fixed rate tasks

I am working on an application which requires it to go online every x minutes and check for some new data. To prevent heavy network and data usage the task should run at fixed rate, but what is the best approach to use for this kind of solution ? A…
Mahmoud
  • 353
  • 1
  • 3
  • 14
6
votes
2 answers

Android Threading: This Handler class should be static or leaks might occur

I am using a handler object to continue UI work after finished a time consuming task in a seperate thread. Had a problem of the above Lint warning and following was my approach. [ Sample Handler object type 1 ] -> Handler responseHandler = new…
JibW
  • 4,538
  • 17
  • 66
  • 101
6
votes
1 answer

The specified message queue synchronization barrier token has not been posted

I have an app which as a binded service. I am sending messages to the service, but sometimes I am getting the following error: E/AndroidRuntime(28216): java.lang.IllegalStateException: The specified message queue synchronization barrier token…
serenskye
  • 3,467
  • 5
  • 35
  • 51
6
votes
3 answers

Execute all scheduled (postDelayed) runnables in Handler

I use a Handler, which post some Runnable via postDelayed(r, DELAY_TIME), but I need to execute all Runnables before posting new via postDelayed. Any good ideas how to achieve this as simple as possible? Edit: I want it basically like…
Leandros
  • 16,805
  • 9
  • 69
  • 108
6
votes
3 answers

How the Looper knows to send the message to Handler?

The question is, where I tell my Thread to use mHandler for the Looper? Thank you. I am using the below code: class LooperThread extends Thread { public Handler mHandler; public void run() { Looper.prepare(); mHandler = new…
Aminadav Glickshtein
  • 23,232
  • 12
  • 77
  • 117
5
votes
4 answers

How to create Life Cycle Aware Handler in Android?

First of all, I know how to create Handler. I am working on a project where I am using Handler with postDelayed. There are some times when app got crashed because activity was destroyed and the task inside the handler executes after activity…
Kishan Solanki
  • 13,761
  • 4
  • 85
  • 82
5
votes
1 answer

Android Handler.createAsync().How does it work?

The doc says it will "Create a new Handler whose posted messages and runnables are not subject to synchronization barriers such as display vsync." What does this mean? When should I use createAsync()?
Xi 张熹
  • 10,492
  • 18
  • 58
  • 86
5
votes
2 answers

How to avoid memory leaks due to custom static handler class?

I have certain memory leaks happening in my custom handler class ,but not sure how to fix it. checkedout a couple of examples online but nothing is specific to my code so not sure how to go about it : private val startupCallback = object:…
user2386226
5
votes
2 answers

Android - Difference between Thread and AsyncTask?

In my app i have buttons, when clicked will query the database and show result on screen. The query action will normally take 1 ~ 3 sec. These buttons will be clicked very often. I've implemented this action on both AsyncTask and Thread but see very…
Tran Ngu Dang
  • 2,540
  • 6
  • 29
  • 38
5
votes
3 answers

android handler removeCallbacks not working

i 'm rotating image with runnable.i want to rotate image for example 4 th time and then pause/stop rotate.i wrote some function public void rotateImage(final View myView, final int size) { runnable = new Runnable() { @Override …
viviano
  • 113
  • 1
  • 7
5
votes
3 answers

AlarmManager vs Handler.postDelayed

In a service which method of delayed execution to be used handler.postdelayed or Alarmmanager. what are the pro and cons. I have 2 services (a) which does background processing and updates the UI via a boradcast message (b) which does some…
user435739
5
votes
2 answers

what happens if I call startService after calling bindService on a service class?

I am calling bindService on a Service MessengerService. It works fine. After that, I call startService. The code is exactly same as this link Remote messenger service example…
IP Archer
  • 135
  • 2
  • 9
4
votes
1 answer

different situations to use AlarmManager vs Handler Android

Could someone explain me different situations to use AlarmManager vs Handler with examples please. Any disadvantages of using these two as alternate to each other? Thanks.
poddroid
  • 845
  • 1
  • 14
  • 26