Kunal Agrawal Kunal Agrawal - 1 month ago 6
Android Question

Launching activity on condition for loginactivity

I want to launch activity after login on 2 condition if user is active in Database entry i want to launch MainActivity.java if user is not active it should launch mobile verification screen i am using volley to make http calls and getting data from server here is my script

LoginActivity.java

// Now store the user in SQLite
String uid = jObj.getString("uid");

JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String phone = user.getString("phone");
String status = user.getString("status");


// Inserting row in users table
db.addUser(name, email, uid,phone);
if(new String(status).equals("active") ) {
// Launch main activity
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
} else{

Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}

Answer

The problem is you are comparing two strings in a wrong way. You should edit

if(new String(status).equals("active") )

to:

if(status.contentEquals("active"))

and you are done.