gpt4 book ai didi

android - 为什么只有最后一个闹钟响了

转载 作者:行者123 更新时间:2023-11-29 17:46:29 25 4
gpt4 key购买 nike

我有一个使用 alarmmanager 的项目。许多 Activity 设置警报,然后当警报上升时,AlarmSetter 名称中的特定 Activity 开始显示警报,并设置新的(下一个)警报和贪睡警报(如果用户需要)。我的问题只是设置的最后一个闹钟。这意味着所有 Activity 都通过最后一个警报设置设置了警报。例如,如果用户选择 snooz 按钮,则在警报 setter 中,主警报不起作用(只是 snooz 也工作 = 最后一个警报 sat)。 我在 G 类(通用)中设置了 alarmmanager,并在 Activity alarm.java 中使用和设置了警报

这是我的 G 类:

public class G extends Application {
public static AlarmManager alarmManager;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
}
}

警报 setter Java IS:

public class ActivityAlarm extends ActivityMain {
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.alarmshower);

//at first reminder will start, should register next alarm time :
long MilisectoAlarmManager = mDbHelper.SetNextTime_andIsactiveYET(DrugRegID);
if (MilisectoAlarmManager != 0 && IsFor10minlater == 0) {
Intent intentMain = new Intent(G.context, ActivityAlarm.class);
intentMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentMain.putExtra("DrugID", String.valueOf(DrugRegID));
intentMain.putExtra("IsItFor10MinLate", String.valueOf(0));
PendingIntent pendingIntentMain = PendingIntent.getActivity(G.context, 0, intentMain, PendingIntent.FLAG_UPDATE_CURRENT);
String AA = mDbHelper.GetStartDateAlarm(DrugRegID);
Date D = new Date(MilisectoAlarmManager);
System.out.println("current Date(ms): " + MilisectoAlarmManager);
G.alarmManager.set(AlarmManager.RTC_WAKEUP, MilisectoAlarmManager, pendingIntentMain);
}



//Finished Activing Alarm Manager and switch Off Alarmn
else if (MilisectoAlarmManager == 0 && IsFor10minlater == 0) {
mDbHelper.UpdateAlarmSwitch(DrugRegID, false);
}

handler.postDelayed(r, HowLongRemainAlarm_var);
//End CountDown Finished Activity

//Procedure for 10 min later button
btn10minLater_var.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
btn10minLater_var.setBackgroundColor(Color.parseColor("#1174b9"));
Intent intentFor10min = new Intent(G.context, ActivityAlarm.class);
intentFor10min.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentFor10min.putExtra("DrugID", String.valueOf(DrugRegID));
intentFor10min.putExtra("IsItFor10MinLate", String.valueOf(1));
PendingIntent pendingIntent10min = PendingIntent.getActivity(G.context, 0, intentFor10min, PendingIntent.FLAG_UPDATE_CURRENT);

G.alarmManager.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + 20000, pendingIntent10min);



ActivityAlarm.this.finish();
}
});

最佳答案

我找到答案了! PendingIntent.getActivity 中的第二个参数在每个闹钟设置中必须不同!

关于android - 为什么只有最后一个闹钟响了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26225183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com