-----------------------------------main.java--------------------------
package com.example.usecount;
import android.support.v7.app.ActionBarActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sharedPreferences = getSharedPreferences("xingye", MODE_WORLD_READABLE);
SharedPreferences.Editor editor = sharedPreferences.edit();
int count = sharedPreferences.getInt("count", 0);
String str = "该应用一共被使用了" + count + "次";
Toast.makeText(this, str , Toast.LENGTH_SHORT).show();
editor.putInt("count", ++count);
editor.commit();
}
}