标签:main shared 支持 nbsp 程序 world support dem oncreate
package sd.he3.sharedpreferencestest; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = findViewById(R.id.button_view); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences.Editor editor = getSharedPreferences("HelloWorld",MODE_PRIVATE).edit(); editor.putString("H","HelloWorld"); editor.apply(); } }); Button button1 = findViewById(R.id.button_2); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences sharedPreferences = getSharedPreferences("HelloWorld",MODE_PRIVATE); String H = sharedPreferences.getString("H",""); Log.d("H++++++++++>>>>>>>>>>>>", H); } }); } }
Android--SharedPreferences数据存储方案
标签:main shared 支持 nbsp 程序 world support dem oncreate
原文地址:https://www.cnblogs.com/yangchaojie/p/9745706.html