samedi 27 janvier 2018

Intent inside if-else for different activities for different user roles

I am developing a project where there are two types of users : Admin and a basic user. With a simple logic i differentiate them. In database, I store is_admin value = 1 for admins and 0 for other users. I have two activity view for that, "AdminViewAcivity" and "UserViewActivty". I need to switch to AdminViewActivity if is_admin=1 and UserViewActivity if is_admin=0. FYI, in database I gave boolean for this, but it automatically converted to tinyint. So, I'm passing int for that.

Here is the code I tried:

int is_admin = jsonResponse.getInt("is_admin");
if (is_admin == 1) {
    Intent intent = new Intent(LoginActivity.this, AdminViewActivity.class);
    intent.putExtra("name", name);
    LoginActivity.this.startActivity(intent);
} else {
    Intent intent1 = new Intent(LoginActivity.this, UserViewActivity.class);
    LoginActivity.this.startActivity(intent1);
}

But now "sign in" itself doesn't work coz of this code inserted. I need help asap. Please help. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire