調用setLastPosition(lastPosition)將值寫入SharedPreference
調用getLastPosition()取得上次寫入SharedPreference的值
int lastPosition = 0; public int getLastPosition(){ //取得SharedPreference設定("Preference"為設定檔的名稱) SharedPreferences settings = getSharedPreferences("Preference", 0); //取出name屬性的字串 lastPosition = settings.getInt("LastPosition", 0); return lastPosition; } public void setLastPosition(int lastPosition){ //取得SharedPreference設定("Preference"為設定檔的名稱) SharedPreferences settings = getSharedPreferences("Preference", 0); //置入name屬性的字串 settings.edit().putInt("LastPosition", lastPosition).commit(); }
沒有留言:
張貼留言