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

how to stop open activity while splash screen killed

I have splash screen . once i open my application the splash screen will appears after completion of splash screen passed intent to HomeActivity. but when i kill this app while splash screen running after some time HomeScreen will automatically…
4
votes
4 answers

Understanding UI thread

For example, there are a lot of tasks are posted to UI thread as follows. Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { @Override public void run() { // Some logic to display/update…
Uma Sankar
  • 449
  • 1
  • 8
  • 19
4
votes
1 answer

Android Thread/Handler Error IllegalStateException: The specified message queue synchronization barrier token has not been posted

What I am trying to do Update TextView on the UI Thread every 3 seconds x 10 times using a Handler and a background thread. The output on the UI should be "Repeat: 1" to begin with and after every 3 seconds, it should ++ the number. Eg "Repeat: 1"…
user7646649
4
votes
4 answers

TextWatcher - cursor goes back to the start of EditText

I've got the following TextWatcher definition: _textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void…
4
votes
1 answer

Update and control multiple CountDownTimer in RecyclerView (pause, resume, delete)

I've implemented to my Android app multiple countdown timers with Service. CountDownTimer is running with service, thus data to fragment is being passed with BroadcastReceiver. I would like to add each timer as a separate item to the RecyclerView…
4
votes
1 answer

Automatically click Button if EditText is correct

I am creating a simple app, I require a button called 'bVoice' to be automatically pressed after 500ms if the EditText field contains the correct information. How do I write the handler to do this in the following code: //Assign button clicks to…
4
votes
2 answers

Most concise way to run a simple background task?

I've seen at least five patterns through which you can have some code to run in a worker thread. Most simple: new Thread(new Runnable() { public void run() { // } }).start(); We can extend AsyncTask; we have AsyncTaskLoader and other…
natario
  • 24,954
  • 17
  • 88
  • 158
4
votes
0 answers

Android after handler removeCallbacksAndMessages still posting runnable in background thread

I encountered an unusual NPE exception in Android with handler and background thread. I know when the activiy or fragment on destroy, the ui widget will be destroied, so you must cancel all the pending message or runnable sent from the…
longkai
  • 3,598
  • 3
  • 22
  • 24
4
votes
1 answer

Use CountDown Timer or roll my own based on Handler in Android

This post: http://android-developers.blogspot.co.uk/2007/11/stitch-in-time.html describes how to implement a timer using a Handler. I could achieve the same thing using a CountDown…
user1977132
  • 487
  • 2
  • 18
4
votes
0 answers

How to send a message to Handler on a dead thread

I have a start and stop job method that checks to see if my connection is maintained. This is for a softphone app so the connection needs to be on as long as the user has the app opened. The code for these methods are below public void startJob(){ …
BigT
  • 1,413
  • 5
  • 24
  • 52
4
votes
1 answer

Android process for "silently" using refresh token to get new access token

I am currently trying to handle a situation in a demo application I'm writing where I have an expired access token, and I need to use a refresh token to get a new access token. Now for background tasks like this, I'd normally use an AsyncTask like…
TheIcemanCometh
  • 1,055
  • 2
  • 17
  • 31
4
votes
3 answers

running a piece of code on separate thread

My doubt is regarding how to run a piece of code within an API in my service, on another thread. I have an API func in my service. Only a part of this API's code, which is independent (2-3 LOC), I want to move it to separate thread, as these take up…
4
votes
6 answers

How to set Delay for loop in android?

I am trying to display a multiplication table with delay. My code is working fine but I am not able to implement the delay. Here is My code: tableButton1 = (Button) findViewById(R.id.Button1); tableButton1.setOnClickListener(new OnClickListener() { …
UchihaSasuke
  • 363
  • 2
  • 23
4
votes
2 answers

Animate drawing of circle/ arc on canvas

Update: 20/11/13: This is still unresolved. I am trying to animate the creation of a circle in a custom view. I would like to animate the creation of the circumference - at the beginning of the animation there is an arc, and by the end of the…
user2442638
4
votes
2 answers

Can I do network operations (UI blocking) inside handlers/runnables?

in my mainActivity, which is the sole activity of my application, I am creating the below handler and running a runnable inside it. I have some misunderstandings about handlers and where they run. See the code Handler handler; @Override …
tony9099
  • 4,567
  • 9
  • 44
  • 73