プリファレンスデータ保存
プリファレンスデータ保存で気になり試験してみた。
・CHR(0)の文字列を保存してその後に呼出して文字列の長さは変わらなかった。
package com.receptorinc.saveandread;
import java.util.Locale;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void btnSave(View v) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = pref.edit();
String buff = "1234567890";
String buff2 = "";
for (int i = 0 ; i < 10; i++) {
buff2 = buff2 + String.format(Locale.US,"%c", 0);
}
buff = buff + buff2;
Toast.makeText(this, "Lengh="+String.valueOf(buff.length()), Toast.LENGTH_LONG).show();
editor.putString("atLog", buff);
editor.commit();
}
public void btnRead(View v) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String buff = sharedPreferences.getString("atLog","");
Toast.makeText(this, "Lengh="+String.valueOf(buff.length()), Toast.LENGTH_LONG).show();
}
}