Questions tagged [postdelayed]
176 questions
7
votes
3 answers
How to kill a PostDelayed Method in Android
I used postedDelayed method to refresh my Activity, which works fine. But the problem is that even when I press the Back button postdelayed method call back the previous activity..
//handler for 30000 milli-secs post delay refreshment of the…

mavHarsha
- 1,056
- 10
- 16
4
votes
3 answers
Running a task at a specific time using postDelayed
I would like to start a task at a specific time. For that I use runnable and postDelayed method as follows:
private Runnable mLaunchTask = new Runnable() {
public void run() {
try {
MY TASK
} catch…

TJ1
- 7,578
- 19
- 76
- 119
4
votes
2 answers
ViewPager2 autoscroll until end of adapter itemCount
I have tried this a few different ways and I havent been able to get this viewpager to perform correctly. I am setting a viewpager2 with an adapter but part of the requirements are that the viewpager be manually swipe-able as well the base on a…

DevinM
- 1,112
- 1
- 12
- 29
4
votes
4 answers
How to execute a function every two seconds in Java on Android?
I'm trying to execute a chunk of Java code in my Android program every two seconds. My code currently looks like this:
LinearLayout.postDelayed(new Runnable() {
public void run() {
//Do stuff here
}
…

josmo
- 41
- 1
- 1
- 4
4
votes
4 answers
Kotlin: How to run a function with delay using extension function
I'm trying to figure out how to use an extension function to run any method with a delay, but can't seem to figure it out.
I am trying something like below where I have a function and I want a handler to delay the execution by a certain…

Rik van Velzen
- 1,977
- 1
- 19
- 37
4
votes
1 answer
how to restart a handler postdelay process if interupted during delay countdown
I have a problem that i can't work out. I have a button that when clicked changes the text view. It then activates a postdelayed process that returns the textview to its original text after 2 seconds.
If i press the button once, and then again…

RhysBailey21
- 117
- 3
- 13
4
votes
1 answer
Android postDelay method's reliability
I am using android.os.Handler's “postDelayed” method to turn ON and OFF a relay. There are 2 runnable - one for sending ON command and another for sending OFF command. The relay needs to be kept on for fixed ms and turned OFF for fixed ms again.
I…

random
- 10,238
- 8
- 57
- 101
4
votes
2 answers
How to stop series of postDelayed handlers
I have a series of postDelayed handlers. I'm having trouble to set a mathode that stops the handlers when the user is tapping on the stop button at any time I he wants.
I'll appreciate any help someone able to provide.
Thanks
while…

RBZ
- 173
- 2
- 9
4
votes
1 answer
How Do I Pause and Resume a For Loop?
I'm a noob to Android and I am trying to cycle text from an arrayList of strings and display them in an textswitcher. I want the text to change every two seconds. i used this SO question as my guide and have no problem switching the text with a…

B. Money
- 931
- 2
- 19
- 56
4
votes
3 answers
How to stop Runnable in Android that's looping using postDelayed()?
I need to stop a Runnable from running when an image is clicked in my Android app. I'm running this Runnable repeatedly using ImageView.postDelayed():
r = new Runnable() {
public void run() {
imgview.setImageResource(imageArray[i]);
…

Amit Prajapati
- 13,525
- 8
- 62
- 84
4
votes
1 answer
nested postDelayed / Runnable / Handler Android
I am trying to use a nested postDelayed because I need to do something after (delayed for) 5 minutes, stop it after (delayed) 30 seconds, do something else, then repeat both events in the cycle again from the start.
I just can't seem to get it…

slinden77
- 3,378
- 2
- 37
- 35
3
votes
1 answer
Handler - postDelayed executes twice
When I use Handler and its postDelayed method, the run() method executes twice. Below is part of my code.
Handler deneme = new Handler();
deneme.postDelayed(new Runnable() {
@Override
public void run()
{
…

Ömer Baykal
- 85
- 8
3
votes
2 answers
How can I pass a variable into a postdelayed runnable?
I have created two classes implemented from runnable(). I then call them several times, with varying delay. The problem is, when I run the runnable later, it needs to know the value of a variable back when the postdelay was called, not when it's…

user1003910
- 41
- 2
- 3
3
votes
2 answers
Runnable is executing slower than expected
I'm using a runnable in my Android app to update a countdown timer, as shown in the code below. It appears to work but I noticed my timer takes a few seconds longer than expected. For example, if it's supposed to count down 3 minutes, it takes 3…

MikeU
- 114
- 1
- 8
3
votes
1 answer
How to stop the launch of a thread done with postDelayed
I have a service tha launch a thread after 15 sec. This is a snippet of my code:
Handler mHandler = new Handler();
OverclockThread ocThread = new OverclockThread();
ocThread.ocPreference = readPreference("oc");
…

Simone
- 795
- 2
- 7
- 17