简体   繁体   中英

Pending alarmManager intent dont fire up when system alarm set up

calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);  
calendar.set(Calendar.HOUR_OF_DAY, 1);
PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context,MyClass.class),PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7*24*60*60*1000, pi);

I have this simple pending repeating alarm and it works just fine only when system android alarm is not set up. It doesnt matter on what time alarms are set in system Alarm app, looks like this system app stops all my pending intents. Any idea how to debug this? What can cause this problem ? I would like to use it in paralel with system alarms.

make sure you have permission

<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

For Debugging:

override onNewIntent() in your activity MyClass Activity like this:

@Override
onNewIntent(Intent intent){
    android.os.Debug.waitForDebugger();
    if(intent.hasExtra("alarm")){           //Put a break point here
        Log.d("Alarm fired","yes");
    }
}

Create you PendingIntent for firing alarm like this:

Intent intent=new Intent(context,MyClass.class);
intent.putExtra("alarm","yes");
PendingIntent pi = PendingIntent.getService(context, 0, intent,0);

So, when your alarm gets fired, control will come to onNewIntent and wait for you to attach a debugger. That time go to Attach debugger button in android studio and attach debugger to your application. And this is how you will know that you alarm has been fired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM