I write code in my MainActivity for repeating alarm and whenever i start my app alarm repeated everytime.But I want it to repeat after every 24 hours
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
sessionManager = new SessionManager(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(getResources().getColor(R.color.black));
setSupportActionBar(toolbar);
repeatAlarm();
}
private void repeatAlarm() {
Date when = new Date(System.currentTimeMillis());
try {
Intent someIntent = new Intent(getApplicationContext(), MyReciever.class); // intent to be launched
// note this could be getActivity if you want to launch an activity
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, // id, optional
someIntent, // intent to launch
PendingIntent.FLAG_CANCEL_CURRENT); // PendintIntent flag
AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, when.getTime(), AlarmManager.INTERVAL_DAY, pendingIntent);
} catch (Exception e) {
e.printStackTrace();
}
}