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

This Handler class should be static or leaks might occur (com.test.test3.ui.MainActivity.1)

I am new to android and i try to develop a system but when i finish code the handler show this warning below show the code after I edit, the handler in event ontounch show the warning handler cannot be resolved. I try putting // to ignore the…
4
votes
3 answers

What is the best practice for a Multithreading Handler on Android?

I have an app, which uses several HTTPRequests for example get a session id get some locationdata get existing categories (...) and some more I created a HTTPRequestHandler, which basically manages all the AsynTasks for each Request... This works…
longi
  • 11,104
  • 10
  • 55
  • 89
4
votes
3 answers

Multiple AsyncTasks issue on Android Spinner

I'm getting some error. I know what is the problem but I don't know how to fix it. I've 4 spinner. Every spinner related one asynctask. For short, When I select one item on spinner1 , execute second asynctask that populate spinner2 (selected item…
3
votes
2 answers

Maintaining a time gap with post vs postDelayed

There are two functions I need to run with a minimum time gap between them. For reasons beyond the scope of this question, at first I was trying to control the timing from a process running in the webview (via a…
drmrbrewer
  • 11,491
  • 21
  • 85
  • 181
3
votes
0 answers

Why is Service object not being garbage collected despite of using WeakReference?

I have a foreground service which plays an alarm for one minute and then closes by itself. I am using Handler for closing the service after one minute by posting a delayed message. The Handler class uses singleton approach (for a reason which is not…
3
votes
1 answer

Handler.postdelay() not working inside recycler view on scroll state change

I'm basically trying to execute a method in my RecyclerView inside on scroll state change here I'm using a Handler thread to execute a method after some delay but the method is not getting executed at all but however if I put that method outside the…
3
votes
1 answer

Android: Handler.post() equivalent in Flutter

In Android, we have Handler.post() method which can run after every fixed time interval like this. Handler handler = new Handler(); handler.post(new Runnable() { public void run() { // ... this runs after every second …
user6274128
3
votes
2 answers

Android: Why isn't there a static method to get the main thread's Handler?

I'm new to Android development. There seem to be 2 important classes when dealing with threading in Android: Looper and Handler. There are static Looper.myLooper() and Looper.getMainLooper() methods to get the current thread's looper and the UI…
James Ko
  • 32,215
  • 30
  • 128
  • 239
3
votes
0 answers

Copious Android log output from Looper/Handler

I am getting copious output in my Android logs, and not from my app. (They persist after uninstall.) As you can see, the culprit might be Google Play Services. The following block of text repeats nine total times (each with a different number in the…
QED
  • 9,803
  • 7
  • 50
  • 87
3
votes
5 answers

Handler doesn't execute again on Activity restart

This code is for my splash screen Activity: @Override protected void onResume() { super.onResume(); handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Intent…
MehDi
  • 504
  • 6
  • 20
3
votes
3 answers

When are runnables posted in postDelayed actually executed on Android?

There is a piece of code where I use postDelayed and some other code executed on the main thread. I ran it a few times and always saw the following output: 07-13 14:22:18.511 15376-15376/sample1.com.sample_1 D/MainActivity: i = 0 .... 07-13…
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
3
votes
3 answers

Android sending messages between fragment and service

I have a fragment with a button. When clicked it tells a service to start polling sensors and then insert the sensor data into a database on a background thread. When the button is pushed again, the service will stop. When the Stop button is pushed,…
3
votes
1 answer

Handler postDelayed in Android Service

In my app there is a Service that is intended to run constantly in background once started. This service is started from an Activity and this is the onStartCommand() method: MyService: .... @Override public int onStartCommand(Intent intent, int…
Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53
3
votes
0 answers

Maximum Time of Post Delayed

I have this method: public static Runnable runAtDate(Date date, final TimerCallback callback) { Date now = new Date(); long timeTo = date.getTime() - now.getTime(); if (timeTo <= 0) { if (callback != null) …
Deukalion
  • 2,516
  • 9
  • 32
  • 50
3
votes
1 answer

Run Handler Task in Android successively

atm i have a problem with my actual Android application. For explanation: At first i want to show a Text in a TextView Char by Char. This is my actual Code for this tvIntro.setText(""); final Handler textHandler = new Handler(); …
Stevetro
  • 1,933
  • 3
  • 16
  • 29