0

タイムピッカーから時間がかかり、仕事をするためにスケジュール時間を設定すると、問題が発生します

 SharedPreferences prefs = getSharedPreferences("CONSTANT_FILE_NAME",Context.MODE_WORLD_WRITEABLE);
             SharedPreferences.Editor editor=   prefs.edit();
             editor.putLong("timepickerhour", timePicker.getCurrentHour());
                editor.putLong("timepickerminute", timePicker.getCurrentMinute());
                editor.putLong("milis", milis);
                editor.commit();



    SharedPreferences prfs = getSharedPreferences("CONSTANT_FILE_NAME",Context.MODE_PRIVATE);
                h =prfs.getLong("timepickerhour",0); 
                m =prfs.getLong("timepickerminute",0); 
                r =prfs.getLong("milis",0);
                AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                Intent intent1 = new Intent(Scheduling.this, Feedback.class);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(Scheduling.this, 0,
                  intent1, PendingIntent.FLAG_UPDATE_CURRENT);
                Calendar calendar1 = Calendar.getInstance();
                calendar1.set(Calendar.HOUR_OF_DAY, (int) h);
                calendar1.set(Calendar.MINUTE, (int) m);
                am.setInexactRepeating(AlarmManager.RTC_WAKEUP,calendar1.getTimeInMillis(),
                        r, pendingIntent);

過去の時間を与えると問題に直面し、今は午後 2 時 25 分に設定した場合、現在の時間は午後 4 時 25 分であり、そのスケジューリング タスクはその場で実行されます。午後 38 時、時刻を午前 4 時 38 分に設定し、コードも実行します。

助けてください

よろしくお願いします

このような同じ問題 Androidでアラームマネージャーを使用して過去のアラームを呼び出すにはどうすればよいですか?

4

2 に答える 2

2
 if (calendar1.before(cal_now)) {// if its in the past increment
                    calendar1.add(Calendar.DATE, 1);
}
于 2013-02-25T10:22:27.523 に答える
0

この行を追加するだけで、適切な時間が得られると思います:---

Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(System.currentTimeMillis());
于 2013-01-08T11:06:39.373 に答える