O addValueEventListener do Firebase funciona apenas por algumas horas
Alguém mais sofreu este problema? Meu código do firebase funciona apenas por basicamente algumas horas (totalmente funcional e tudo) e, quando tento novamente, não funciona mais. Veja o código abaixo para saber como eu estou chamando:
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.e(TAG, "onDataChange: Job found");
for (DataSnapshot jobSnapShot : dataSnapshot.getChildren()) {
Log.e(TAG, "onDataChange: Job +1");
Job job = jobSnapShot.getValue(Job.class);
// Add the ID into the job
job.setId(dataSnapshot.getKey());
// Set the job
arrayList.add(job);
subscriber.onNext(job);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e(TAG, "onCancelled: " + databaseError.getMessage());
}
};
Log.e(TAG, "call: id:" + userId + ", reference:" + FirebaseDatabase.getInstance().getReference().toString());
Log.e(TAG, "call: Calling Jobs...");
FirebaseDatabase.getInstance()
.getReference()
.child(context.getString(R.string.firebase_jobs))
.child(userId).
addValueEventListener(valueEventListener);
As linhas:
Log.e(TAG, "call: id:" + userId + ", reference:" + FirebaseDatabase.getInstance().getReference().toString());
Log.e(TAG, "call: Calling Jobs...");
Execute sempre. UserId e getReference retornam valores corretos. No entanto, o addValueEventListener não parece adicionar o ouvinte depois de várias horas depois. A única maneira de corrigir isso é fazer logoff e logon novamente.
EDITAR:
Meu código de ouvinte do estado de autenticação:
firebaseAccount = getFirebaseAccount();
firebaseAccount.getAuth().addAuthStateListener(firebaseAccount.getAuthListener());
Em firebaseAccount:
public FirebaseAuth.AuthStateListener getAuthListener() {
return authStateListener;
}
FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
if (firebaseUser != null) {
String id = firebaseUser.getUid();
// User is signed in
Log.e(TAG, "onAuthStateChanged: Signed in as " + id);
// Start loginActivity when signed in
loginActivity.onLoginSuccess(id);
} else {
// User is not signed in
Log.e(TAG, "onAuthStateChanged: Signed out");
// User probably logged out. Finish the loginActivity and launch the login screen
}
}
};