I'm working on a project in which I have to save details of the user before logging him/her in her account so that I don't have to fetch his/her detail again and can refer to that class whenever I need their details. It's displaying the toast "Error occurred ! please login again." which means null value or false is being returned. Also after I close the app and open again its moving to next Activity.
signintouserbycredential method
private void signInTheUserByCredential(PhoneAuthCredential credential)
{
firebaseAuth=FirebaseAuth.getInstance();
firebaseAuth.signInWithCredential(credential).addOnCompleteListener(Login_student.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
String curr_user_str=task.getResult().getUser().getUid();
//Store user data in HelperClass for future use
if((curr_user_str.isEmpty())&&(storeUserInfoInHelperClass(curr_user_str)))
{
Toast.makeText(Login_student.this, "Login Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Login_student.this, Home_page.class));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
finishAffinity();
}
else
{
Toast.makeText(Login_student.this,"Error occurred ! Please login again.",Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(Login_student.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
storeInfoinHelperClass method
int flag=0;// to check if data is stored and if it is stored return true
static HelperClass data;
public boolean storeUserInfoInHelperClass(String curr_user_str) {
reff = FirebaseDatabase.getInstance().getReference("userdetails");
reff.child(curr_user_str).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (data != null) {
data = dataSnapshot.getValue(HelperClass.class);
flag=1;
} else {
flag=0;
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
if(flag==1)
return true;
else
return false;
}