handler or timer android

后端 未结 3 2071
不思量自难忘°
不思量自难忘° 2020-12-10 15:01

i\'m tryin\' to display a msg every 1 min!! non stop! i found exemple that display the msg just one time after a fixed delay!! can you help how can set it?? or if using time

3条回答
  •  臣服心动
    2020-12-10 15:20

    Try this code -

    public class TimertestActivity extends Activity {
        Handler handler = new Handler();
        Runnable runnable = new Runnable() {
            public void run() {
                afficher();
            }
        };
    
        /** Called when the activity is first created. */
    
          @Override   
          public void onCreate(Bundle icicle) {   
            super.onCreate(icicle);   
            setContentView(R.layout.main);  
            runnable.run();
          }   
    
          public void afficher()
          {
              Toast.makeText(getBaseContext(),
                         "test",
                         Toast.LENGTH_SHORT).show();
              handler.postDelayed(runnable, 1000);
          }
    }
    

提交回复
热议问题