SharedPreferences storage, which is often used for storing some configuration items in the program. It is much simpler to use than symbian, and the code is very simple. It is used for testing. You can also try other methods.
The Code is as follows:
Xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<TextView
Android: id = "@ + id/info"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>
<Button
Android: id = "@ + id/btnwrite"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "write"
/>
<Button
Android: id = "@ + id/btnread"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "read"
/>
</LinearLayout>
Java code
Package zziss. android. prefertest;
Import android. app. Activity;
Import android. content. SharedPreferences;
Import android. OS. Bundle;
Import android. view. View;
Import android. widget. Button;
Import android. widget. TextView;
Public class Prefer_testActivity extends Activity {
/** Called when the activity is first created .*/
Private TextView info;
Private Button btnw;
Private Button btnr;
SharedPreferences sp;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Info = (TextView) this. findViewById (R.id.info );
Btnw = (Button) this. findViewById (R. id. btnwrite );
Btnr = (Button) this. findViewById (R. id. btnread );
Sp = this. getPreferences (MODE_PRIVATE );
Btnw. setOnClickListener (new View. OnClickListener (){
@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
SharedPreferences. Editor ed = sp. edit ();
Ed. putString ("info", "this is the stored message ");
Ed. commit ();
}
});
Btnr. setOnClickListener (new View. OnClickListener (){
@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
Info. setText (sp. getString ("info ",""));
}
});
}
}
You can use the file manager in DDMS to open data \ data, find your project, and find the shared_prefs directory to find the stored file, in xml format.
The content of the file stored above is
<? Xml version = '1. 0' encoding = 'utf-8' standalone = 'Yes'?>
<Map>
<String name = "info"> This is the stored message </string>
</Map>