2

SQLite を使用して複数のアラームを設定しましたが、時計を設定すると、最後に設定したアラームが 1 つしかありません。どうすればこれを修正できますか?

public class alert extends Activity{


    DatePicker pickerDate;
    TimePicker pickerTime;
    Button buttonSetAlarm;
    Button insertButton;`enter code here`
    TextView info;

    Context mContext; 
    AlarmManager mAlarmManager;

    dalAlarm dbAlarm ;
    SQLiteOpenHelper dbHelper;
    SQLiteDatabase database;

    final static int RQS_1 = 0;

    dalAlarm dalAl = new dalAlarm(this);


    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alertscreen);


        info = (TextView)findViewById(R.id.info);
        pickerDate = (DatePicker)findViewById(R.id.pickerdate);
        pickerTime = (TimePicker)findViewById(R.id.pickertime);

        Calendar now = Calendar.getInstance();
        pickerDate.init(
                now.get(Calendar.YEAR), 
                now.get(Calendar.MONTH), 
                now.get(Calendar.DAY_OF_MONTH), 
                null);

        pickerTime.setCurrentHour(now.get(Calendar.HOUR_OF_DAY));
        pickerTime.setCurrentMinute(now.get(Calendar.MINUTE));

        buttonSetAlarm = (Button)findViewById(R.id.setalarm);
        buttonSetAlarm.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                Calendar current = Calendar.getInstance();

                Calendar cal = Calendar.getInstance();
                cal.set(pickerDate.getYear(), 
                        pickerDate.getMonth(), 
                        pickerDate.getDayOfMonth(), 
                        pickerTime.getCurrentHour(), 
                        pickerTime.getCurrentMinute(), 
                        00);

                //dbAlarm.addNewAlarm(new dalHelper_alarm(pickerTime.getCurrentHour(),pickerTime.getCurrentMinute(),cal.getTime().toString()));
                if(cal.compareTo(current) <= 0){

                    Toast.makeText(getApplicationContext(), 
                            "Invalid Date/Time", 
                            Toast.LENGTH_LONG).show();
                }else{

                    //  dbAlarm.addNewAlarm(new dalHelper_alarm(pickerTime.getCurrentHour(),pickerTime.getCurrentMinute(),cal.getTime().toString()));


                    setAlarm(cal);

                    database();

                }

            }

        });



    }


    public void setAlarm(Calendar targetCal)
    {

        info.setText("\n\n***\n"
                + "Alarm is set@ " + targetCal.getTime() + "\n"
                + "***\n");

        dalAlarm db = new dalAlarm(alert.this);

        dalHelper_alarm test = new dalHelper_alarm(pickerTime.getCurrentHour(),pickerTime.getCurrentMinute(),targetCal.getTime().toString());

        db.addNewAlarm(test);





    }


    public void newAlarm(Calendar newCal){


        Intent intent = new Intent(getBaseContext(), popUp.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
        AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, newCal.getTimeInMillis(), pendingIntent);  
    }

    public void database(){


        ArrayList<dalHelper_alarm> alarm = dalAl.getAllAlarm();
        Calendar newCal = Calendar.getInstance();



        newCal.set(pickerDate.getYear(), 
                pickerDate.getMonth(), 
                pickerDate.getDayOfMonth(), 
                alarm.get(0).getHour(), 
                alarm.get(0).getMin(), 
                00);
        info.setText("\n\n*** \n"
                + "Alarm is set@ " + newCal.getTime() + "\n"
                + "***\n");

        newAlarm(newCal);



    }
}
4

1 に答える 1

0

PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, インテント, PendingIntent.FLAG_ONE_SHOT);

同じリクエスト コード (0) を使用しています。それをアラームごとに一意のものに変更します(おそらくYYYYMMDDHHMMSS?)。

于 2015-02-11T22:38:06.297 に答える