public class MainActivity extends Activity
{
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sharedPreferences = getSharedPreferences("count", MODE_WORLD_READABLE);
int count = sharedPreferences.getInt("count",0);
Toast.makeText(this,"程序以前被使用了"+count + "次。",Toast.LENGTH_LONG).show();
editor = sharedPreferences.edit();
editor.putInt("count",++count);
editor.commit();
}
}
SharePreference之记录应用的使用次数
最新推荐文章于 2023-03-28 16:57:12 发布