package com.urey; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.widget.TextView; public class PreferencesDemo extends Activity { private TextView tv; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SharedPreferences shp= PreferenceManager.getDefaultSharedPreferences(this); int count = shp.getInt("count", 0); tv = (TextView)findViewById(R.id.text); tv.setText("程序被使用"+(count++)+"次"); SharedPreferences.Editor seditor = shp.edit(); seditor.putInt("count", count); seditor.commit(); } }