0
爲什麼吐司只顯示一個空字符串或任何我輸入作爲上的getString線的「默認」值SharedPreferences返回一個空字符串
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sharedPreferences = this.getSharedPreferences("com.example.stefan.dijeljenepreference", Context.MODE_PRIVATE);
sharedPreferences.edit().putString("username", "stefan");
String username = sharedPreferences.getString("username","");
Toast.makeText(this,"username:" + username, Toast.LENGTH_SHORT).show();
}
缺少的putString – Rizwan
後應用調用您未使用適用()或提交()編輯後,這就是爲什麼 –
真棒,這是它,謝謝。 –