2017-03-18 8 views
1

こんにちは、スイッチを使用してアラームを無効にしてアラームを発生させ、特定のアラームIDをSQLデータベースから取得しようとしています。私はまだそれに取り組んでいるが、誰かがすばやく見ることができればそれは素晴らしいだろう。リストビューアダプタにアラームを作成スイッチを使用してアラームをキャンセルする

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(); 

      } 

現在のエラーメッセージ.....ヌルオブジェクト参照に 'ボイドandroid.content.Intent.prepareToLeaveProcess(android.content.Context)' 仮想メソッドを呼び出す

試み

答えて

0

この2行を忘れることがないように修正しました。

alarmManager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE); 
receiver = new Intent(view.getContext(), Alarm_Reciever.class); 
関連する問題