I am new to Android Developing and I'm experiencing some problem and I can't really tell from my point of view why the app sending me back to login and I checked the Codes line by line what is the problem. I just change my Home design and the code in my Home.java is still the same but when I run the application when i tap the MainActivity it sent me back to Login, but
when I change the intent Activity in Login > MainActivity it works fine
but if Login > Home > MainActivity then it always sent me back in Login. How come that user is getting null after changing the Activity from Home.
Home.java
if (mAuth.getCurrentUser() != null) {
mUserRef = FirebaseDatabase.getInstance().getReference().child("Users").child(mAuth.getCurrentUser().getUid());
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId())
{
case R.id.nav_users:
Intent intent = new Intent(Home.this,MainActivity.class);
startActivity(intent);
case R.id.nav_logout:
logout();
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser==null)
{
sendToStart();
}
}
private void sendToStart()
{
Intent startIntent = new Intent(Home.this, LoginActivity.class);
startActivity(startIntent);
finish();
}