Reputation: 3830
I am calling BroadcastReceiver on Some Time Input, but I am getting 10-15 seconds delay in onReceive of Broadcast.
Activity.class
Intent intent = new Intent(DashboardActivity.this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(DashboardActivity.this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeinMillis, pendingIntent);
TimeAlarm.class
public class TimeAlarm extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
Debug.e("RECEIVER_TIME", "ALARM_READY");
Upvotes: 0
Views: 945
Reputation: 19288
Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested. https://developer.android.com/reference/android/app/AlarmManager.html
If it is really important that there is no delay, use setExact
for API 19,20 and 21 and use setExactAndAllowWhileIdle
for API 23 and 24.
Upvotes: 2