SharedPreferences sp = getSharedPreferences("flightConfig", Context.MODE_PRIVATE); sp.edit().putString("flightNumber", flightNumber); sp.edit().apply();
SharedPreferences sp1 = getSharedPreferences("flightConfig", Context.MODE_PRIVATE); String flightNumber2 = sp1.getString("flightNumber", ""); System.out.println("flightNumber2:" + flightNumber2);
看着没毛病吧,就是不好使,脑袋都挠大了~
这么写就行了,我去: SharedPreferences.Editor editor = sp.edit(); editor.putString("flightNumber", flightNumber); editor.putString.... editor.apply();
这个edit()方法每次都new一个,伤不起。
|