add inside the runner:
handler.postDelayed(this, 1000);
Why doesn't this postDelayed run forever?
-
23-03-2022 - |
Question
This is my code, but in theory it should keep posting this log message every second until forever, but it doesn't. Any ideas? My goal is to have it run forever, but a while loop also doesn't work.
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
public class Blink extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blink);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Log.d("AAA", "Test");
}
}, 1000);
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow