doushao5047 2015-11-01 16:34
浏览 43
已采纳

从php webservice获得结果“成功”时打开另一个活动但是没有用,android

I have used a php webservice where i am matching login credentials if true i pass "success", if false i pass "failure".

and In java code, i am matching result data and apply condition when will open another activity and when will show a toast for wrong credentials.

But when i put either wrong or right credentials it will always open another activity. never show a toast

So please help me , what should I do ?

my code

 @Override
    protected void onPostExecute(String result) {
        String str = result.trim();
        if(str=="success") {
            startActivity(new Intent(Login.this,MainActivity.class));
        }
        else{
            Toast.makeText(Login.this, "Either Username or Password is not correct", Toast.LENGTH_SHORT).show();
        }
        dialog.dismiss();
    }

my php code

$sql = "select * from master_login_tbl where user_id = '$user' or email='$user' and password = '$pass' ";
$result = mysql_query($sql);
$check = mysql_fetch_array($result);
$num_of_rows = mysql_num_rows($result);
if($num_of_rows > 0){echo "success";}else{echo 'failure';}
  • 写回答

1条回答 默认 最新

  • drxdai15012937753 2015-11-01 17:20
    关注

    You need to use str.equals("success"), comparing strings in Java with == does not work because you compare the objects and not the string.

    You can also use equalsIgnoreCase("success)", which, as the name suggests, ignores any upper or lower case differences.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题