使用开关取消警报
Cancel alarm using a switch
你好,我正在尝试使用开关禁用和报警,并从 SQL 数据库中获取特定的报警 ID,目前,每当我尝试禁用它时,我都会收到一个空引用。我现在仍在努力,但如果有人也可以快速浏览一下,那就太好了。
在列表视图适配器上创建警报
final int id = (int) System.currentTimeMillis();
pendingIntent = PendingIntent.getBroadcast(v.getContext(), id, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, myCalendar.getTimeInMillis(), pendingIntent);
intentArrayList.add(pendingIntent);
我尝试从 BaseAdapter 取消数据库。
mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cursor.moveToPosition(position);
if (mySwitch.isChecked()){
Toast.makeText(view.getContext(), Integer.toString(position) + "ENABLED", Toast.LENGTH_SHORT).show();
} else {
String id = cursor.getString(cursor.getColumnIndexOrThrow("alarm_code"));
pendingIntent = PendingIntent.getBroadcast(view.getContext(), Integer.valueOf(id), receiver, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.cancel(pendingIntent);
Toast.makeText(view.getContext(), "DISABLED", Toast.LENGTH_SHORT).show();
}
当前错误信息.....
尝试在空对象引用上调用虚拟方法'void android.content.Intent.prepareToLeaveProcess(android.content.Context)'
修复了如果您不忘记将这两行输入的错误
alarmManager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE);
receiver = new Intent(view.getContext(), Alarm_Reciever.class);
你好,我正在尝试使用开关禁用和报警,并从 SQL 数据库中获取特定的报警 ID,目前,每当我尝试禁用它时,我都会收到一个空引用。我现在仍在努力,但如果有人也可以快速浏览一下,那就太好了。
在列表视图适配器上创建警报
final int id = (int) System.currentTimeMillis();
pendingIntent = PendingIntent.getBroadcast(v.getContext(), id, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, myCalendar.getTimeInMillis(), pendingIntent);
intentArrayList.add(pendingIntent);
我尝试从 BaseAdapter 取消数据库。
mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cursor.moveToPosition(position);
if (mySwitch.isChecked()){
Toast.makeText(view.getContext(), Integer.toString(position) + "ENABLED", Toast.LENGTH_SHORT).show();
} else {
String id = cursor.getString(cursor.getColumnIndexOrThrow("alarm_code"));
pendingIntent = PendingIntent.getBroadcast(view.getContext(), Integer.valueOf(id), receiver, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.cancel(pendingIntent);
Toast.makeText(view.getContext(), "DISABLED", Toast.LENGTH_SHORT).show();
}
当前错误信息.....
尝试在空对象引用上调用虚拟方法'void android.content.Intent.prepareToLeaveProcess(android.content.Context)'
修复了如果您不忘记将这两行输入的错误
alarmManager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE);
receiver = new Intent(view.getContext(), Alarm_Reciever.class);