Java 意图不能正常工作

Java 意图不能正常工作,java,android,android-intent,request,http-post,Java,Android,Android Intent,Request,Http Post,我已经创建了代码。Intent未打开,在两种情况下都会执行默认的Intent。我尝试了从if else语句到,但得到了相同的结果。有人可以检查我的代码并提供帮助。提前谢谢 StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String re

我已经创建了代码。Intent未打开,在两种情况下都会执行默认的Intent。我尝试了从if else语句到,但得到了相同的结果。有人可以检查我的代码并提供帮助。提前谢谢

StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        //If we are getting success from server
        switch (response) {
            case "success": {
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);
            }
            default:
                Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
            }
      }
}
StringRequest-StringRequest=new-StringRequest(Request.Method.POST,url,new-Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
//如果我们从服务器获得成功
开关(响应){
“成功”案例:{
Intent Intent=新的Intent(getApplicationContext(),MainActivity.class);
星触觉(意向);
}
违约:
Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG.show();
}
}
}

break;
添加到您的
案例“成功”结尾处:

如果您的开关盒末尾没有某种类型的
中断
返回
,它只会继续到下一个盒。这就是为什么您会看到
吐司


官方文档:

那么字符串不能是
“success”
。您能使用调试器查看它的值吗?我已经做了每件事,将字符串更改为整数1和0,但结果相同。每次运行default和else语句时都会忽略条件结构。即使在默认情况下,toast也会打印success。但为什么不在条件中呢。