0
나는 사용자가 동전을 모을 때마다 표시되는 동전이라는 int를 가지고있다. 활동이 표시 될 때마다 0으로 설정되지만 누적 된 결과를 다른 페이지에 표시하려고합니다. 나는 totalCoins
하지만 응용 프로그램이 사망하고 재개 될 때마다, totalCoins이 다시 0으로 설정되어 내가 사용하여 공유 환경 설정으로 저장 해봤를 표시 한Android : 저장된 int를 누적하는 방법?
if (counter == 0) {
totalCoins += coins;
counter++;
}
: 이것은 내가 결과를 축적 한 방법이다 0 동전을 설정하고 여전히 활동이 재 작성 될 때를 축적하면서, 방법
private void putValue(String name, int value) {
SharedPreferences sp = getSharedPreferences("sharedPreferences", 0);
SharedPreferences.Editor prefEditor = sp.edit();
prefEditor.putInt(name, value);
prefEditor.commit();
}
private int getValue(String name, int defaultValue) {
SharedPreferences sp = getSharedPreferences("sharedPreferences", 0);
return sp.getInt(name, defaultValue);
}
한 다음 putValue("TotalCoins", totalCoins);
사용 totalCoins = getValue("TotalCoins", 0);
어떻게 양의 동전을 축적합니까?