In my code user signs in to Firebase with Google like explained in:
https://firebase.google.com/docs/auth/android/google-signin
This works fine.
When a user opens the program, it loads the initialization values from the firebase database. Here is the code:
private void loadPrefsFromDB() {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
uid = user.getUid();
FirebaseDatabase.getInstance().getReference().child("users").child(uid)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
userPrefs = dataSnapshot.getValue(UserPrefs.class);
updateUI(userPrefs);
Log.d(TAG, "loadPrefsFromDB:onDataChange");
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "loadPrefsFromDB:onCancelled");
}
});
}
This works well when the wifi connection is turned off, but if i open the program wifi on, the function does not trigger. If, while the program is running, I click the wifi off and the phone switches to mobile data I instantly get login:
D / MainActivity: loadPrefsFromDB: onDataChange
The function also gets triggered if I sign out and again in with wifi on. Shouldn't firebase handle this situation? Or do I need to refresh authentication somehow?