开发者

Will AlarmManager run two instances of the same alarm at once?

开发者 https://www.devze.com 2023-04-01 07:59 出处:网络
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开发者_如何

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消