Intent 与 SharedPreferences 传送与接收数据

发送数据:

spSetings=getSharedPreferences("NamePwd", MODE_PRIVATE);
Editor edit=spSetings.edit();
edit.putBoolean("isKeep", false);
edit.putString("username", "");
edit.putString("password", "");
edit.commit();

Intent intent=new Intent(MainActivity.this,SuccessActivity.class);
intent.putExtra("username", etUserName.getText().toString());
intent.putExtra("password", etPassWord.getText().toString());
startActivity(intent);

接收数据:

SharedPreferences sp=getSharedPreferences("NamePwd", MODE_PRIVATE);
String spuser=sp.getString("username", "");
String sppass=sp.getString("password", "");
tv2.setText("用户名:"+spuser+"密码:"+sppass);

Intent intent=getIntent();
String user= intent.getStringExtra("username");
String pass=intent.getStringExtra("password");
tv.setText(tv.getText().toString()+":"+user+":"+pass);

原文地址:https://www.cnblogs.com/liumin-txgt/p/13156201.html