Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Handler has an active task?

Tags:

java

android

If I have a Handler handler = new Handler() and run a delayed task for it handler.postDelayed(xxx, xxx), is that possible to check has the postDelayed() was called or not?

like image 422
Eugene Avatar asked Apr 18 '13 08:04

Eugene


People also ask

How do I know if runnable is running?

Runnable runnable = ( ) -> { System. out. println( "Running the runnable at " + Instant. now() ); }; ScheduledExecutorService scheduledExecutorService = Executors.

What is new handler () postDelayed?

postDelayed(Runnable r, Object token, long delayMillis) Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. final void. removeCallbacks(Runnable r)

What is the use of handlers?

A Handler allows communicating back with UI thread from other background thread . This is useful in android as android doesn't allow other threads to communicate directly with UI thread. A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue.


1 Answers

is that possible to check has the postDelayed() was called or not?

One quick fix, in method assign some boolean variable to true and then just perform checking.

like image 76
Simon Dorociak Avatar answered Sep 18 '22 02:09

Simon Dorociak