且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Android 中设置多个闹钟?

更新时间:2023-01-29 19:10:29

好的,当你设置一个 PendingIntent 时,你应该给它分配一个唯一的 ID,以防你以后想识别它(用于修改/取消它)

Ok, when you set an PendingIntent, you're supposed to assign it a unique ID to it, incase you want to identify it later (for modifying/canceling it)

static PendingIntent    getActivity(Context context, int requestCode, Intent intent, int flags) 
//Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent).
static PendingIntent    getBroadcast(Context context, int requestCode, Intent intent, int flags) 
//Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().

请求代码就是那个 ID.

The Request code is that ID.

在您的代码中,您不断重置 SAME PendingIntent,而是每次使用不同的 RequestCode.

In your code, you keep resetting the SAME PendingIntent, instead use a different RequestCode each time.

PendingIntent pIntent = PendingIntent.getActivity(context,uniqueRQCODE, newIntent, 0);

它必须是一个整数,我想你有一个primaryid (itemId) 可以从警报B 中识别警报A.

It has to be an integer, i suppose you have a primaryid (itemId) that can identify Alarm A from Alarm B.