Search code examples
androidconditional-statementszbar

Scan result QR condition


i created a QR code scanner with zbar here
i wanna make some condition for example like this

 // define scan result
 // scanResult = "toolkit1"; 
 Toast.makeText(this, scanResult, Toast.LENGTH_SHORT).show();
 if (scanResult == "toolkit1")
    Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
 else 
    Toast.makeText(this, "fail : " +scanResult, Toast.LENGTH_SHORT).show();

i'm very sure if scanResult from my app is 'toolkit1'
but everytime i launch app it's go to fail section

but if i define manual scan result var, it's not have problem
any idea why i can't perform simple condition in zbar?


Solution

  • Shouldn't you be using .equals() for String comparison? The == could work too, but that depends on the JVM optimizing the String resources in your app...