handler or timer android

后端 未结 3 2072
不思量自难忘°
不思量自难忘° 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:13

    You can use TimerTask for this.But when your device goes sleep it will not working so i think you can use AlarmManager for this. Anyway refer this link for TimerTask ,

    AlarmManager code,

    AlarmManager am = (AlarmManager) Context.getSystemService(Context.ALARM_SERVICE);
    am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime(), interval, pendingIntent);
    

提交回复
热议问题