Android 登录活动与截击,php,mysql登录成功后意图不去其他活动

Android 登录活动与截击,php,mysql登录成功后意图不去其他活动,android,login,Android,Login,我使用Volley、php、MYSQL和共享首选项创建了我的登录应用程序。 登录和注册活动成功,但页面在登录成功后不会转到其他活动。这是一个意图还是另一个问题?请帮忙 登录活动: //if everything is fine StringRequest stringRequest = new StringRequest(Request.Method.POST, URLs.URL_LOGIN, new Response.Listener() {

我使用Volley、php、MYSQL和共享首选项创建了我的登录应用程序。 登录和注册活动成功,但页面在登录成功后不会转到其他活动。这是一个意图还是另一个问题?请帮忙

登录活动:

//if everything is fine StringRequest stringRequest = new StringRequest(Request.Method.POST, URLs.URL_LOGIN, new Response.Listener() { @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(); } } } //如果一切顺利 StringRequest StringRequest=新的StringRequest(Request.Method.POST,URL.URL\u登录, 新的Response.Listener(){ @凌驾 公共void onResponse(字符串响应){ progressBar.setVisibility(View.GONE); 试一试{ //将响应转换为json对象 JSONObject obj=新的JSONObject(响应); //如果响应中没有错误 如果(!obj.getBoolean(“错误”)){ Toast.makeText(getApplicationContext(),obj.getString(“消息”),Toast.LENGTH_SHORT.show(); //从响应中获取用户 JSONObject userJson=obj.getJSONObject(“用户”); //创建新的用户对象 用户=新用户( userJson.getInt(“id”), userJson.getString(“全名”), userJson.getString(“电话”) ); //将用户存储在共享首选项中 SharedPrefManager.getInstance(getApplicationContext()).userLogin(user); //启动配置文件活动 完成(); startActivity(新意图(getApplicationContext(),ProfileActivity.class)); }否则{ //出错时 Toast.makeText(getApplicationContext(),“Ops!”+obj.getString(“message”),Toast.LENGTH\u SHORT.show(); } }捕获(JSONException e){ e、 printStackTrace(); } } } 将此更改为

   //starting the profile activity

   finish();
   startActivity(new Intent(getApplicationContext(), ProfileActivity.class));


在您开始下一个活动后,应该通过将finish()移动到来修复此错误。因为它不是,我认为您实际上根本没有到达那一行代码。您确实到达了设置toast的那一行,因此您的错误必须介于那一行和startactivity行之间

我认为您在这里可能有一个错误:

                           JSONObject userJson = obj.getJSONObject("user");

                            //creating a new user object
                            User user = new User(
                                    userJson.getInt("id"),
                                    userJson.getString("fullname"),
                                    userJson.getString("phone")
                            );

密钥-用户、id、全名或电话-可能不存在。当您尝试访问它们时,您会收到一个错误,阻止代码到达更改活动的行。请检查日志猫或运行控制台,查看我的预感是否正确。

尝试使用本地上下文,例如,如果您在Mainactivity而不是Maina中如果您在片段中,请尝试使用getactivity(),我认为它应该可以正常工作。

我只是显示了一个Toast“登录成功”…不更改为其他活动..您想在登录成功后转到profileactivity,对吗?是的,先生..我想在登录成功后获得profile activity..您能帮我吗,先生.在清单中,我已放置了登录和配置文件活动类..当我尝试时,一切正常..祝酒词显示成功..只有成功登录后我不能转到其他活动..您呢在日志中解析JSON是否有任何预期?您可以尝试向intent添加标志。intent intent=new intent(LoginActivity.this,ProfileActivity.class);intent.setFlags(intent.flag\u ACTIVITY\u CLEAR\u TOP);startActivity(intent);finish();好的,先生..我已经这么做了..但仍然是一样的..仅显示toast消息..尝试在startActivity之后记录一条消息,以确保代码行已执行。还要查看LogCat中是否存在引用应用程序上下文的异常。请参阅显示的图像,其中显示无法从应用程序上下文启动活动xt
                           JSONObject userJson = obj.getJSONObject("user");

                            //creating a new user object
                            User user = new User(
                                    userJson.getInt("id"),
                                    userJson.getString("fullname"),
                                    userJson.getString("phone")
                            );