简体   繁体   中英

Setting up alarm for X amount of times

I have a question about alarms. Is it possible to set up an alarm so that it repeats X amount of times only? Like currently in the google docs, the setRepeating() repeats forever like shown in the code below:

 manager.setRepeating(AlarmManager.RTC_WAKEUP,timeInMillis, interval, pendingIntent);

where interval let's say is weekly in millis: interval = 604800000;

How do I make it so that it repeats only eg weekly for 3 times only? So something to set alarm X amount of times where X can be 3 or 5 or whatever the user sets?

store check value in SharedPreference ( called count), when alarm fire, increase it and store back to SharedPreference. When count = the integer that user sets. You cancle alarm X and set it again, do not forget set count = 0.

let the pendingIntent forward to BroadCastReceiver. When Alarm was trigger, then OnCreate() method called. Do some stuff follow your ideal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM