アンドロイドでsharedpreferencesを使用してアンドロイドにデータを保存しています。sharedpreferences内の保存されたデータを閉じて再度開くと表示されませんか?
私はデータを正常に保存できますが、近いアプリケーションと保存されたデータを表示していないかどうかはわかりません。
マイコード:
public class MainActivity extends Activity {
EditText editText;
Button button;
Button button1;
TextView text;
public static final String mypreference = "MY_PREFS_NAME";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
button1 = (Button) findViewById(R.id.button2);
text = (TextView) findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences shared = getSharedPreferences(mypreference, MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
editor.putString("mn",editText.getText().toString());
editor.commit();
SharedPreferences prefs = getSharedPreferences(mypreference, MODE_PRIVATE);
String ap = prefs.getString("mn","");
text.setText(ap);
}
});
保存されているとはどういう意味ですか?それをどうやってテストするのですか? – Vega
不必要な詳細を削除する 'i'を' I'に変更する – user7294900