android - 登录成功后使用 volley、php、mysql 登录 Activity Intent 不进入其他 Activity

标签 android authentication

我使用 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/

相关文章:

java - 从android中的url加载图像

java - 在 flutter 应用程序中集成 GoogleTez 时出错

android - 禁止特定的第 3 方应用程序和系统消息记录到 LogCat

java - 如果 AttributeSet 是一个接口(interface),它如何从 xml 中存储/检索值?

php - 如何在每个页面上验证用户 session

android - 如何在 Android 中获取当前月份的 Facebook 好友生日列表

java - 无法在与 java.net.URLConnection 的一个 session 中使用不同的 NTLM 凭据进行身份验证

python - Django 登录需要两次

android - 在 web 服务器中创建 session 以供 android 应用程序访问

authentication - CakePHP:获取模型中的用户信息