知乎专栏 |
目录
new Handler().postDelayed(() -> { picture.browsePictureFolder(); }, 30000);
new Handler().postDelayed(new Runnable() { @Override public void run() { MainActivity.this.finish(); } }, 1800);
Android 11
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { public void run() { progressBar.setVisibility(View.INVISIBLE); } }, 3000);
循环执行
Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { int count = 5; @Override public void run() { handler.postDelayed(this, 1000); runOnUiThread(() -> { binding.textViewAdSkip.setText(String.format("逃过 %d", count)); }); count = count - 1; if (count == 0) { handler.removeCallbacks(this); binding.frameLayoutAd.setVisibility(View.INVISIBLE); binding.frameLayoutFullscreen.setVisibility(View.VISIBLE); } } }, 1000);