我使用 Volley、php、MYSQL 和共享首选项创建了我的登录应用程序。 登录和注册 Activity 成功,但登录成功后页面不去其他 Activity 。是 Intent 还是其他问题?
登录 Activity :
//if everything is fine
StringRequest stringRequest = new StringRequest(Request.Method.POST, URLs.URL_LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressBar.setVisibility(View.GONE);
try {
//converting response to json object
JSONObject obj = new JSONObject(response);
//if no error in response
if (!obj.getBoolean("error")) {
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
//getting the user from the response
JSONObject userJson = obj.getJSONObject("user");
//creating a new user object
User user = new User(
userJson.getInt("id"),
userJson.getString("fullname"),
userJson.getString("phone")
);
//storing the user in shared preferences
SharedPrefManager.getInstance(getApplicationContext()).userLogin(user);
//starting the profile activity
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
} else {
// when error
Toast.makeText(getApplicationContext(), "Ops! "+obj.getString("message"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
最佳答案
将此更改为
//starting the profile activity
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
到
startActivity(new Intent(LoginActivity.this, ProfileActivity.class));
finish();
关于android - 登录成功后使用 volley、php、mysql 登录 Activity Intent 不进入其他 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46424742/