我使用此示例代码删除当前通知工作正常,但我想知道此代码中的此计时器在做什么?我想每 19 秒删除一次通知,所以在我的代码中有两个计时器,如果我想每 30 分钟删除一次通知,我会更改哪个计时器?这个tewo计时器的功能是什么?myTimer.schedule(myTask, 19 * 1000 , 19 * 1000);
如果我每 30 分钟发出一次删除通知,我会更改哪一个???
public class TimeAlarm extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "CherryApplication";
CharSequence message = "Launcher application for games.";
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();
Intent startMyActivity = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
startMyActivity, 0);
Notification notif = new Notification(R.drawable.cherry_icon,
"CherryApplication", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
myTimer.schedule(myTask, 19 * 1000, 19 * 1000);
}
class MyTimerTask extends TimerTask {
public void run() {
nm.cancel(1);
System.out.println("");
}
}
}