2
In a method that records a AlarmManager
to run every 30 seconds BroadcastReceiver
:
public void play(View view) {
Log.i("lgg", "Botão: broadPlay");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
long intervalo = 30 * 1000;
Intent tarefaIntent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent tarefaPendingIntent = PendingIntent.getBroadcast(this, 0, tarefaIntent, 0);
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
intervalo, tarefaPendingIntent);
}
Broadcastreceiver:
public class Mybroadcastreceiver extends Broadcastreceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("lgg", "onReceive " + new Date());
}
But accompanying the Log
, I see what time it performs at the correct interval, no time, hour takes 1min or even more, etc.
I wonder why it happens ?
And what method do the big apps (e.g. Whatsapp) use for real-time checking ?