Search code examples
androidif-statementtoast

non of IF/ElSE works on SDK Build version


I use this simple condition check to show a Toast but none of them is shown:

 public void ShowVersion(){

         //This works So I am sure the method is called:
         //Toast.makeText(this,"Method is called",Toast.LENGTH_LONG).show();

        if (Build.VERSION.SDK_INT >= 23) {
            Toast.makeText(this,"Version Supported",Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this,"Version not supported",Toast.LENGTH_LONG).show();
        }
    }

How it is possible that none of if and else work?


Solution

  • The main problem was an exception inside the IF block. The exceptions breaks IF / ELSE block. A try/catch block can help detect problem in similar cases.