1.首先在登录页面跳转到下一页面的时候保存登录名
SharedPreferences sprfMain; SharedPreferences.Editor editorMain;
//保存登录名(存数据)Intent intent = new Intent(act, MainActivity.class); final String phone = et_phone.getText().toString();sprfMain = getSharedPreferences("counter", Context.MODE_PRIVATE);editorMain = sprfMain.edit();editorMain.putString("phone", phone);editorMain.commit();startActivity(intent);
结合之前的保存登录状态一起用,跳转到下一页面就可以读取数据了
//取出上个页面保存的值(取数据) sprfMain = getSharedPreferences("counter", Context.MODE_PRIVATE); String phone = sprfMain.getString("phone", ""); tv_phone.setText(phone);
然后在首页填了手机号就可以在第二个页面显示了,跳过登录之后第二次进入第二个页面之后数据还在,注销账号再清除数据。
如果还想在其他页面还显示用户名的话继续取数据就行了