Alaram Manager in android
I'm having code which is to be run daily, for this I'm trying to use Alarm
manager. This is my code for triggering alarm.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this, AlarmReciever.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.cancel(pi); // cancel any existing alarms
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY,
AlarmManager.INTERVAL_DAY, pi);
}
This part of code is calling AlarmReciever class as expected, but I want
the code in AaramReciever class to be executed once daily. But its being
called multiple times. How do I restrict it?
No comments:
Post a Comment