Android:如何使用异步任务返回值检查条件

时间:2014-03-09 07:55:11

标签: android android-asynctask

我正在异步任务中进行一些处理以检查服务器上的某些值,如果值存在服务器php脚本返回true,否则为false。

一切正常,但每当我尝试使用http响应字符串检查条件时,条件永远不会被检查..

部分代码:

CheckDevice cd = new CheckDevice();
String chk[] = new String[1];
    chk[0] = di.imei;
    try {
        cd.execute(chk).get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

cd.getFinalResult(); //This returns string "true" (working outside if);


    if(cd.getFinalResult == "true"){
            //This loop never executes... why?
    regButton.setEnabled(false);
        regButton.setText("Device Already Registered");
        Toast.makeText(getApplicationContext(), cd.getFinalResult(), Toast.LENGTH_LONG).show();
    }

有什么问题?有人请告诉......

1 个答案:

答案 0 :(得分:3)

DO,

  cd.getFinalResult().equals("true") //OR

  cd.getFinalResult().equalsIgnoreCase("true")

因为您无法使用(==)比较字符串。

查看this了解详情。