Intent intent = new Intent(this.getIntent()); // 데이터를 넘겨 받기 위한 Intent
year = intent.getIntExtra("dYear",1); // 데이터 넘겨 받기
month = intent.getIntExtra("dMonth", 1) + 1;
day = intent.getIntExtra("dDay",1) - 1;
savePreferences3();
calendar.set(year, month, day);
calendar.add(java.util.Calendar.MONTH, 21); // +21개월
dday.setText(calendar.get(Calendar.YEAR) + "/" +
numformat.format(calendar.get(Calendar.MONTH)) + "/" +
numformat.format(calendar.get(Calendar.DATE))); // D day 텍스트 변경
다른 액티비티에서 데이터받고, 출력을 하고 있습니다
출력되는 텍스트 dday 를 유지하기 위해서 savepreference를 사용했어요
사용한 부분은 다음과 같습니다
// 입대일 데이터 저장
private void savePreferences3() {
SharedPreferences pref = getSharedPreferences("pref3", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("year2", year);
editor.putInt("month2", month);
editor.putInt("day2", day);
editor.commit();
}
// 입대일 데이터 호출
private void getPreferences3() {
SharedPreferences pref = getSharedPreferences("pref3", MODE_PRIVATE);
SaveYear = pref.getInt("year2", 0);
SaveMonth = pref.getInt("month2", 0);
SaveDay = pref.getInt("day2", 0);
}
private void show() {
getPreferences3();
final Calendar calendar = java.util.Calendar.getInstance();
calendar.set(SaveYear, SaveMonth, SaveDay);
calendar.add(java.util.Calendar.MONTH, 21); // +21개월
dday.setText(calendar.get(Calendar.YEAR) + "/" +
numformat.format(calendar.get(Calendar.MONTH)) + "/" +
numformat.format(calendar.get(Calendar.DATE))); // D day 텍스트 변경
데이터 저장하는 함수, 불러오는 함수, 출력함수 이렇게 3개 정의해놓은 부분입니다.
show() 함수를 어디에 호출하든간에 원하는 값이 안나옵니다.
처음에 앱을 키고 dYear, dMonth, dDay 설정하면 액티비티에서 값 제대로 전달받고, 출력도 잘 합니다ㅠㅜ
근데 앱 다시키면 그 출력을 유지하지 못하네요
다른 액티비티에서도 위와 같은 방법으로, 데이터 저장 , 호출, 출력 다 했는데ㅠㅠ 여기선 뭐가 문제인지 모르겠어요
하루가 멀다하고 질문해서 부끄러워요( ..) 혼자 해결할줄도 알아야하는데 아직 많이 부족하네요...ㅎㅎ