Advertisement
Sketchware

Passa os segundo e fecha app com 30 segundos

Jan 12th, 2023
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.59 KB | None | 0 0
  1. final EditText editText = (EditText) findViewById(R.id.editText1);
  2.  
  3. Timer timer = new Timer();
  4. timer.scheduleAtFixedRate(new TimerTask() {
  5.     @Override
  6.     public void run() {
  7.         Calendar c = Calendar.getInstance();
  8.         int seconds = c.get(Calendar.SECOND);
  9.         final String time = String.valueOf(seconds);
  10.         runOnUiThread(new Runnable() {
  11.             @Override
  12.             public void run() {
  13.                 editText.setText(time);
  14.                 if (time.equals("30")) {
  15.                     finish();
  16.                 }
  17.             }
  18.         });
  19.     }
  20. }, 0, 1000);
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement