I am calling the following code two times in my application. Will Android start a second alarm if one alarm is already running and the code is called again, or will it run only one at a tim开发者_如何学JAVAe?
Intent recurringIntent = new Intent(MY_INTENT);
recurringIntent.setPackage(MY_PACKAGE_NAME);
PendingIntent recurPendingIntent = PendingIntent.getBroadcast(context, 0 /* requestCode */, recurringIntent, 0 /* flags */);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), STATS_TIME_INTERVAL, recurPendingIntent);
If you use the same intent and request code to create the PendingIntent, your previous alarm will be overwritten.
精彩评论