1.介绍
2.使用方法
3.java后台
package com.lucky.test46sharedpreferences_apply; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity { SharedPreferences sharedPreferences; SharedPreferences.Editor editor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //实例化SharedPreferences,参数1为name(随意命名即可)、参数2为数据存储的模式 sharedPreferences=getSharedPreferences("lucky",MODE_WORLD_READABLE); editor=sharedPreferences.edit(); int count=sharedPreferences.getInt("count",1); //读取数据 Toast.makeText(MainActivity.this,count+"",Toast.LENGTH_SHORT).show(); editor.putInt("count",++count); //放入需要存储的数据 editor.commit(); //数据提交,注意:一定不能忘 } }