According to this question need the background service.
How to keep a service running in background even after user quits the app?
I tried to do that, but i can not identify where should i call the alarm manager inside the service.
MyService.java
This is i tried service class.
public class MyService extends Service{
PendingIntent pendingIntent;
AlarmManager alarmManager;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Query the database and show alarm if it applies
// I don't want this service to stay in memory, so I stop it
// immediately after doing what I wanted it to do.
pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 280192, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 11);
calendar.set(Calendar.MINUTE, 55);
calendar.set(Calendar.SECOND,00);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
// stopSelf();
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
// // I want to restart this service again in one minute
// AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
// alarm.set(
// alarm.RTC_WAKEUP,
// System.currentTimeMillis() + (1000 * 60 * 1),
// PendingIntent.getService(this, 0, new Intent(this, MyService.class), 0)
// );
}
}
Please guide me to give the reminder to user to specific time period even application not running. Thank You