Questions tagged [postdelayed]

176 questions
269
votes
5 answers

cancelling a handler.postdelayed process

I am using handler.postDelayed() to create a waiting period before the next stage of my app takes place. During the wait period I am displaying a dialog with progress bar and cancel button. My problem is I can't find a way to cancel the postDelayed…
Ron
  • 2,723
  • 2
  • 15
  • 5
142
votes
6 answers

Stop handler.postDelayed()

I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; …
basti12354
  • 2,490
  • 4
  • 24
  • 43
78
votes
4 answers

How to remove a runnable from a handler object added by postDelayed?

I have an "open" animation and am using Handler.postDelayed(Runnable, delay) to trigger a "close" animation after a short delay. However, during the time between open and close, there is possibly another animation triggered by a click. My question…
Bruce Lee
  • 3,049
  • 3
  • 20
  • 13
51
votes
5 answers

How to use postDelayed() correctly in Android Studio?

I have a countDownTimer and if the user does not hit the gameButton within the 12th second I want the gameOver method called. The problem is that either the game function instantly gets called when the countDownTimer is 12 or the timer just keeps…
Ryder Thacker
  • 1,472
  • 3
  • 13
  • 33
46
votes
8 answers

Android - running a method periodically using postDelayed() call

I have a situation in an Android app where I want to start a network activity (sending out some data) which should run every second. I achieve this as follows: In the onCreate() I have the code: tv = new TextView(this); tv.postDelayed(sendData,…
zolio
  • 2,439
  • 4
  • 22
  • 34
23
votes
6 answers

Updating UI with Runnable & postDelayed not working with timer app

I have looked at every discussion and thread I can find on getting this to work but it is not. I have a simple timer that updates a text view (mTimeTextField in the example below). The mUpdateTimeTask run method is being executed correctly (every…
bdelliott
  • 463
  • 1
  • 7
  • 12
17
votes
3 answers

Android Testing Handler.postDelayed

I'm newbie on Android and get stuck on testing a SplashScreen, basically what I'm doing is trying to test that the splash screen stays on for 3s. this is the code for the splashScreen @Override protected void onStart() { super.onStart(); …
Rabel
  • 171
  • 1
  • 1
  • 4
16
votes
3 answers

How to change/reset handler post delayed time?

I'm using postDelayed method of the Handler in order to perform an action after certain amount of time: private static int time_to_wait = 2000; Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { // Make…
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
16
votes
2 answers

How to delay execution android

I am building an android board game which features AI. The AI gets a turn and has to invoke a series of actions after which it posts invalidate to my custom view to update. I need to slow down these actions so the user gets to see the AI having its…
Luke De Feo
  • 2,025
  • 3
  • 22
  • 40
14
votes
2 answers

Android: use handler post.delayed twice

I would like to know if it's possible to use handler().postdelayed twice? I mean, I want to create a button, that when clicked it change the color and stay in this state 1 second, then, after 1 second another button change the color. I've created…
loading27
  • 153
  • 1
  • 1
  • 5
12
votes
2 answers

How to get an Android widget's size after layout is calculated?

I have a layout which specifies sizes of widgets in relative dimension, for example:
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
10
votes
6 answers

handler.postDelayed is not working in onHandleIntent method of IntentService

final Handler handler = new Handler(); LOG.d("delay"); handler.postDelayed(new Runnable() { @Override public void run() { LOG.d("notify!"); //calling some methods here } }, 2000); The "delay" does shows in the log, but not…
10
votes
5 answers

How to loop or execute a function every 5 seconds on Android

How can I loop that time() function on the onCreate every 5 seconds.. help me I'm a newbie in Android =) ... I want to execute time() function in onCreate every 5 seconds. public void onCreate(Bundle savedInstanceState) { time(); //<-- How can i…
Chong
  • 115
  • 1
  • 1
  • 7
10
votes
2 answers

Pausing with handler and postDelayed in android

I'm very new to android programming so please forgive my noobie-ness. I'm trying to create a very simple activity that will have one TextView in the middle of the Layout and just have it switch to a different text every couple of seconds. For…
John Octavious
  • 221
  • 1
  • 3
  • 9
8
votes
2 answers

When exactly is onUserInteraction() called?

in my app I got a thrad that checks every 60s data from a webservice (defined in onCreate()): new Thread(new Runnable() { @Override public void run() { while (true) { try { …
1
2 3
11 12