Hi I am using alarm Manager for specific time interval for 3 minutes and I started monitoring. It worked for sometimes and suddenly I noticed there is irregular time interval which is not correct! You can see in attached log where at "20-Jul-2016 12:22:03 pm" time varies! I connected the phone and turned off the screen and monitored! where for every 3 minutes, i hit the server and gets the response as 1. But at one time, it takes 5 minutes to hit the server! Why this strange issue happened?
Here is code.
public void startAt3() {
Intent alarmIntent = new Intent(ActivityTracking.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(ActivityTracking.this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
/* Set the alarm */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
/* Repeating on every 3 minute interval */
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(),
180000L, pendingIntent);
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
Log.e("alarm",mydate);
}
AlarmReceiver:
public class AlarmReceiver extends WakefulBroadcastReceiver {//AlarmReceiver class
@Override
public void onReceive(Context context, Intent intent) {//onReceive method
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
Log.e("alarm",mydate);
Intent service = new Intent(context, SimpleWakefulService.class);//intent to call another class
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, service);//service started
}
SimpleWakefulService:
public class SimpleWakefulService extends IntentService {
public SimpleWakefulService() {
super("SimpleWakefulService");//instantiates simpleWakefulService
}
@Override
protected void onHandleIntent(Intent intent) {
Log.e("simpleWakeful","simpleWakeful");
serviceCall(this); //here is downloadTaskMethod called and getting response as 1.
}