0

これを使用して共有設定を保存しようとしています

SharedPreferences sharedPref = getSharedPreferences("BluefreeSharedPreferences",0); 
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
prefEditor = sharedPref .edit();
prefEditor.putString("UserName", userName);
prefEditor.putString("Password", password);
prefEditor.commit();

2.2.1 の Samsung Galaxy 1900 では共有設定が保存されませんが、2.2.1 のエミュレータと 4.0.3 OS の HTC Y one では正常に動作します。ここでいくつかの投稿を読みましたhttp://code.google.com/p/android/issues/detail?id=14359誰でも私を導くことができます それはまだ問題ですか?

4

1 に答える 1

0

エディターを正しく初期化していないと思います。これは私が少し前に書いた小さなコードです。カウンターを優先し、実行時にインクリメントします

SharedPreferences counter = getSharedPreferences("prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor count_editor = counter.edit();
int currentCount = counter.getInt(packageName +"", 0);
currentCount++;
count_editor.putInt("times clicked", currentCount);
count_editor.commit();

これを試してください http://developer.android.com/guide/topics/data/data-storage.html#pref

于 2012-06-10T10:58:09.893 に答える