I am very new to android studio and could really use your help. i am having problem with logIn page code where after login using firebase auth. i would retrive a int value from firestore in login page and then decide where to go next(layout). it always goes to main activity rather personaldetails2(i.e, the if condition is always false even the value inside fristtimekey = 1).
please check where the problem is at if(fristtimekey ==1), other then that ever thing is correct(logcat is correct too with value 1 in it).
here my code:
fAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(Login.this, "LogedIn succesfully", Toast.LENGTH_SHORT).show();
userid = fAuth.getCurrentUser().getUid();
DocumentReference docRef = foster.collection("users").document(userid);
DocumentReference document = foster.document("users/email");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
fristtimekey = document.getLong("Frist time");
Log.d("TAG", String.valueOf(fristtimekey));
Log.d("TAG", "DocumentSnapshot data: " + document.getLong("Frist time") + " int: " + fristtimekey);
} else {
Log.d("TAG", "No such document");
}
} else {
Log.d("TAG", "get failed with ", task.getException());
}
}
});
progressBar.setVisibility(View.GONE);
if (fristtimekey == 1) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
} else {
startActivity(new Intent(getApplicationContext(), PersonalDetails2.class));
}
} else {
Toast.makeText(Login.this, "LogedIn unsuccesfully", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});