toast not working and also else if

272 views Asked by At

In this code else if part is not working . toast is not appearing if login failed .

my code

try {
    s= json.getString("info");
    Log.d("Msg", json.getString("info"));
    if(s.equals("success")) {
        Intent login = new Intent(getApplicationContext(),MainPage.class);
        login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(login);                    
        finish();            
    } else if(s.equals("fail")) { 
        Toast.makeText(getParent(),"Login Failed",
        Toast.LENGTH_SHORT).show();
        ((EditText) findViewById(R.id.user)).setText("");
        ((EditText) findViewById(R.id.pwd)).setText("");
        finish();
    }
1

There are 1 answers

2
moffeltje On BEST ANSWER

Try changing this:

Toast.makeText(getParent(),"Login Failed", Toast.LENGTH_SHORT).show();

To:

Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_SHORT).show();