Questions tagged [postdelayed]
176 questions
1
vote
3 answers
How do I avoid a handler.postDelayed(Runnable run) from being called?
I have this method to scan Bluetooth LE devices. The scanner runs asynchronously for 10s and then it is interrupted.
public void startScanning() {
Handler handler = new Handler();
final long SCAN_PERIOD = 10000;
handler.postDelayed(new…

raff5184
- 344
- 1
- 2
- 15
1
vote
1 answer
Run a method periodically using ktx handler extensions
UPDATE: Clarification, I am looking for an extension to run a function every 1000 ms for example, without needing to use handler.postDelayed twice.
I've recently started using the android-ktx Kotlin extensions. And I've run into the handler…

Aleks Nine
- 249
- 7
- 15
1
vote
4 answers
handler.postDelayed vs. AlarmManager vs
I have a minor problem in one of my apps. It uses a BroadCastReceiver to detect when a call finishes and then performs some minor housekeeping tasks. These have to be delayed for a few seconds, to allow the user to see some data and to ensure that…

alibi
- 866
- 1
- 8
- 11
1
vote
1 answer
postDelayed() not working in Android service with START_STICKY and startForeground
I have a service
class BusLocationService : Service()
which is started as START_STICKY and shows a permanent notification.
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
if (intent.action ==…

Slawa
- 1,141
- 15
- 21
1
vote
1 answer
handler.postDelayed() not stopping
I am updating my UI using the handler.postDelayed() but it is not stopping when I'm wanting it to stop. it keeps updating the UI.
int progress = 10;
Runnable mStatusChecker = new Runnable() {
@Override
public void run() {
try {
…

TheNoob
- 37
- 6
1
vote
2 answers
Simon Says button color won't return to normal after button press
public void flashButton(int color) {
final ImageView colors = findViewById(R.id.buttonsImage);
final int newColor = color;
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
…

m.rights
- 13
- 3
1
vote
1 answer
Delay SMS sending ANDROID
I'm currently trying to code an app to send mass SMS to 300+ numbers I have in my database.
I'm facing issues with sending them all at one go my app will force close and I only managed to send like 27/308.
I'm using a for loop to send my SMSes.
Is…

Royston
- 15
- 1
- 6
1
vote
3 answers
Detecting long presses in Android
I'm trying to detect a long press in Android. GestureDetector is deprecated, so I was trying to use Handlers. But handler isn't recognizing postDelayed or removeCallbacks. It Cannot resolve method for either.
final Handler handler = new…

stumped
- 3,235
- 7
- 43
- 76
1
vote
1 answer
Handler#removeCallbacksAndMessages not working properly
I created an h.postdelayed and I want to cancel that if a condition is true.
I wrote the if condition and inside it I did h.removeCallbacksAndMessages(null). However, I can see the "timer" still running. Any help?
h.postDelayed(new Runnable() {
…

FreeLine
- 71
- 1
- 10
1
vote
1 answer
postdelayed Handler doesn't repeat the runnable
I try to run this code to get the status of the user from my database. The process includes JSON, so I make a new class implements Runnable to act as background service. I did create a class extends Service. In that Service I call the thread. I use…

Dhani Himawan
- 49
- 5
1
vote
1 answer
condition signal from handler postDelayed?
I'm very new to Android programming so pls excuse my ignorance...
I'm trying to do simple Android app:
User presses a button, starts postDelayed job and then waits on conditional var
after timeout the postDelayer job should signal
private final…

V0idd
- 95
- 1
- 7
1
vote
2 answers
Service in an AlarmReceiver is not getting called in Android
In my app, this is how notifications should work:
An AlarmReceiver gets triggered at a fixed time period in the day.
This AlarmReceiver start a service.
This service calls a post() method to delay the execution by 5 seconds.
The code in this post()…

Sid
- 1,270
- 2
- 15
- 30
1
vote
1 answer
Why charging state of the phone affects my app's behavior
I have a Runnable r that is triggered periodically once per minute by handler.postDelayed(60*1000). And I test my code on a real device.
However I notice, when the phone is charging (AC or USB) , it works well, but if the phone is disconnected,…

Zhang Yifan
- 233
- 1
- 2
- 7
1
vote
1 answer
How the method postDelayed(Runnable runnable, Long delayMilliSeconds) works exactly?
I want to know when the method postDelayed(...) is executed and there are many messages that are waiting in the message queue. In that case, when the runnable will be runned ? is it gonna be after the time defined in the method elapses ? or it will…

HiddenDroid
- 1,440
- 4
- 14
- 27
1
vote
2 answers
How to add some delay after each iteration of array, each iterations changes view's property. Android
Lets say i have an array of char (mCharArray), and one textView (tvChar) that is the size of the whole screen. i want that, when the user clicks the screen (the tvChar), the textView shows each char inside the charArray, however it should have like…

Wellyanto the second
- 19
- 4