0
정수를 "매일"지정된 시간에 재설정해야합니다. 필자의 활동에서 Shared 환경 설정에 매일 값을 기록한 다음 알람 관리자와 브로드 캐스트 리시버로 값을 0으로 설정하려고합니다. 공유 환경 설정 외에 모든 것이 작동하며 값은 여전히 그대로 유지됩니다. 공유 된 환경 설정에 대해 다른 컨텍스트를 가져와야한다고 생각합니다. 어떤 도움을 환영합니다. 정수를 특정 시간에 매일 재설정하십시오.
수신기 :public void onReceive(Context context, Intent intent) {
final SharedPreferences shared = context.getSharedPreferences("Mydata", MODE_PRIVATE);
final SharedPreferences.Editor editor = shared.edit();
int sum = shared.getInt("data1", 0);
Calendar c = Calendar.getInstance();
String date = String.valueOf(c.get(Calendar.DATE));
mainData.insert_data(date, sum);
int zero = 0;
editor.putInt("data1", zero);
editor.apply();
}
알람 매니저 : 메인 활동에
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 22);
calendar.set(Calendar.MINUTE, 45);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
final Context context = this.getContext();
PendingIntent pi = PendingIntent.getService(context, 0,
new Intent(context, MyAppReciever.class),PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pi);
공유 환경 설정 :
final SharedPreferences shared = this.getContext().getSharedPreferences("Mydata", MODE_PRIVATE);
final SharedPreferences.Editor editor = shared.edit();
editor.putInt("data1", 0);
editor.putInt("month", 0);
final int today212 = shared.getInt("data1", 0);
final int mesec212 = shared.getInt("month", 0);
final int limit212 = shared.getInt("budget", 0);
당신이 BroadcastReceiver''에서'SharedPreferences'를 업데이트하는 방법은 무엇입니까? – mklimek
예, 그게 문제라고 생각합니다 –
나는 그렇게 생각하지 않습니다. 'Integer'가 업데이트되지 않았 음을 어떻게 확인합니까? – mklimek