I have created two back ground services in my application. I have to start my back ground service with in some intervals. So I am using alarm for this. One service have to start for every 15 minutes and another one for once per day. My code is here.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 15);
Intent intent = new Intent(this, TestService.class);
pintent = PendingIntent.getService(this, 0, intent, 0);
alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);;
i=15;
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), i*1000, pintent);
if (networkInfo != null && networkInfo.isConnected())
{
startService(new Intent(getBaseContext(), TestService.class));
}
else
{
}
I used like this. Its works finely in first time. Which means my alarm starts again after 15 mints in first time. Then it repeating for every 15 seconds. I don't know how to set the time properly for this. Can any body tell me to achieve this? Thanks in advance.