I need to trigger a block of code after 20 minutes from the AlarmManager being set.
Can someone show me sample code on how to use an AlarmManager in ِAndroid?
I have been playing around with some code for a few days and it just won’t work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“Some sample code” is not that easy when it comes to
AlarmManager.Here is a snippet showing the setup of
AlarmManager:In this example, I am using
setRepeating(). If you want a one-shot alarm, you would just useset(). Be sure to give the time for the alarm to start in the same time base as you use in the initial parameter toset(). In my example above, I am usingAlarmManager.ELAPSED_REALTIME_WAKEUP, so my time base isSystemClock.elapsedRealtime().Here is a larger sample project showing this technique.