How to login a specific user to selected activity

51
October 09, 2019, at 4:00 PM

This app can register 2 main users student and teacher after registering the users they can login if the user is a teacher there will be a toast msg saying teacher if it's a student there will be a toast saying student in the register page student and teacher will selected by a checkbox

this is the code i tried

cursor = db.rawQuery("SELECT * FROM " + DatabaseHelper.TABLE_USER + " WHERE " + DatabaseHelper.NAME + "=? AND " + DatabaseHelper.PASSWORD + "=?", new String[]{user,pass});
                if(username.getText().toString().trim().length() == 0 ||
                        password.getText().toString().trim().length() == 0){
                    toast(MainActivity.this,"All fields are required");
                }
                else if (cursor != null){
                    if(cursor.getCount() > 0){
                        if(DatabaseHelper.TYPE.equals("Teacher")){
                            toast(MainActivity.this,"Teacher");
                        }
                        else{
                            toast(MainActivity.this,"Student");
                        }
                    }
                    else {
                        toast(MainActivity.this,"Not Found");
                    }
                }
                else{
                    toast(MainActivity.this,"Error");
                }
            }
        });

When i tried to login it always return Student what did i do wrong

Answer 1

It is not much information to analyze but the line:

if(DatabaseHelper.TYPE.equals("Teacher")){

looks not correct. You need something like :

if(cursor.getString(cursor.getColumnIndex(TYPE)).equals("Teacher")){

if TYPE is the name of column in which you store the string "Teacher".

READ ALSO
How can I load an image from URL without extension

How can I load an image from URL without extension

I'd like to load an image from a URL but it doesn't work because the link doesn't have an extension Can this be solved??? URL example : http://d1s5a4e3za7rnicloudfront

33
How to get value from TypedArray without passing default value

How to get value from TypedArray without passing default value

I'm using the below code to retrieve values from TypedArray in a custom view, but there is something I don't getIf I'm passing default style as 4th parameter then why I have to use getXXXX(R

33
How do you track screens as pages on Google Analytics? (website view using app data)

How do you track screens as pages on Google Analytics? (website view using app data)

We have an Android app we'd like to track pages using Google Analytics withI've integrated the Google Analytics SDK through Play Services 17

36
Notification not receive when Application terminated in android

Notification not receive when Application terminated in android

I use firebase push notification to device tokenWhen app is opening or in foreground I can get notification well

53