【发布时间】:2016-10-03 20:33:41
【问题描述】:
有人遇到过这个问题吗?我的firebase代码基本上只能工作几个小时(功能齐全),然后当我再次尝试时它不再工作了。请参阅下面的代码了解我如何称呼它:
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);
线条:
Log.e(TAG, "call: id:" + userId + ", reference:" + FirebaseDatabase.getInstance().getReference().toString());
Log.e(TAG, "call: Calling Jobs...");
每次都执行。 UserId 和 getReference 返回正确的值。但是,基本上几个小时后,addValueEventListener 似乎并没有添加监听器。解决此问题的唯一方法是注销并重新登录。
编辑:
我的身份验证状态监听器代码:
firebaseAccount = getFirebaseAccount();
firebaseAccount.getAuth().addAuthStateListener(firebaseAccount.getAuthListener());
在 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
}
}
};
【问题讨论】:
-
新 Firebase 的 android 身份验证存在问题,今天太平洋时间 12:00 将发布该问题的更新,这听起来与此问题 github.com/firebase/quickstart-andr 类似的行为...
-
status.firebase.google.com/incident/Authentication/16001 这是 Firebase 更新
-
您好,来自 Firebase 身份验证团队的 Alfonso。上述事件已在 9.0.2 中解决。这应该是无关的 :) 您可以在登录用户后尝试运行以下代码吗?这会强制刷新用户令牌,这可能是这里失败的原因。 gist.github.com/alfongj/44bdab03de37224c44a274bfb35e7b6b 请让我们知道这是否正常工作或引发异常。
-
好的。您可以放心地忽略 GoogleSignatureVerifier 消息,它只是来自 google play 的日志,有时可能会显示但不会影响行为(Google play 团队正在努力使其看起来不那么可怕)。为了解决您的问题,请您关注these steps,然后从我上面的要点重新运行代码,并报告它是否有效。
-
感谢您这么快就将答案标记为已接受 :)
标签: android firebase firebase-realtime-database