我有一个应用程序,你可以将图像上传到我公司的服务器所以用户输入他们的登录详细信息、电子邮件、密码和 clientID(4 位代码)(在 LoginActivity.java 中),然后必须将此信息传递给所有其他活动,这传递的信息然后用于构建 URL。现在我遇到的问题是 Sharedprefrences 没有正确共享......它们要么在 url 上显示为 NULL,要么只是“电子邮件”或“密码”信息在登录活动中正确保存但是当我尝试通过它失败的其他活动
在这里登录活动我保存首选项
public class LoginActivity extends AppCompatActivity implements TextWatcher {
SharedPreferences MyPrefs;
Intent intent;
SharedPreferences.Editor editor;
public static final String PREF_NAME= "MYPREFS";
public static final String ID = "ClientID" ;
public static final String EMAIL = "username" ;
public static final String PASS = "password";
EditText email, password, id;
@SuppressLint("CommitPrefEdits")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button buttonOne=findViewById(R.id.button);
buttonOne.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent activity2Intent=new Intent(getApplicationContext(), MainActivity.class);
startActivity(activity2Intent);
}
});
MyPrefs= getSharedPreferences(PREF_NAME, 0);
editor = MyPrefs.edit();
email=findViewById(R.id.emailtext);
password=findViewById(R.id.pwdtext);
id=findViewById(R.id.clientid);
email.setText(MyPrefs.getString(EMAIL,"username"));
password.setText(MyPrefs.getString(PASS,"password"));
id.setText(MyPrefs.getString(ID, "id"));
email.addTextChangedListener(this);
password.addTextChangedListener(this);
id.addTextChangedListener(this);
MyPrefs =getSharedPreferences(EMAIL,0);
MyPrefs =getSharedPreferences(ID,0);
MyPrefs =getSharedPreferences(PASS,0);
intent = new Intent(LoginActivity.this,CameraActivity.class);
}
MMMHUHU
慕码人8056858
相关分类