How To Log In Two Different Types Of Users To Different Activities Automatically Without Having To Log In Again?
There's this android application I'm building with Firebase as the backend. It requires two different sets of users, a set of lecturers and a set of students. There's an issue howe
Solution 1:
publicclassLoginActivityextendsAppCompatActivity {
privateTextInputLayout mLoginEmail;
privateTextInputLayout mLoginPassword;
privateProgressDialog mLoginProgress;
privateFirebaseAuth mAuth;
privateFirebaseAuth.AuthStateListener mAuthListener;
privateDatabaseReference jLoginDatabase, student_token_reference, lecturer_token_reference;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mLoginProgress = newProgressDialog(this);
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
String uid = mAuth.getCurrentUser().getUid();
fDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
fDatabase.addValueEventListener(newValueEventListener()
{
@OverridepublicvoidonDataChange(DataSnapshot dataSnapshot)
{
if(uid.equals(dataSnapshot.child("key"))
{
// Open Student Activity
}
else
{
// Open Lecturers Activity
}
}
I am unaware of your database collections. So take them appropriately.
Solution 2:
If you use the FirebaseAuth
+ FirebaseDatabase
you can do it picking the type of the user. So in your model add the String type
attribute. When the user login is not null check:
if(user.getType().equals("student1")){
startActivity(intentStudent1);
} else if(user.getType().equals("student2")){
startActivity(intentStudent2);
}
And the fathers tree of your database will be the email of the student, I use it in my app mayking it in Base64 code/uncode
so the email elaine@gmail.com
will be ZWxhaW5lQGdtYWlsLmNvbQ==
.
I use it to get the status...
Post a Comment for "How To Log In Two Different Types Of Users To Different Activities Automatically Without Having To Log In Again?"