【发布时间】:2017-12-10 22:33:43
【问题描述】:
在我的新 Android 应用(使用 MVP 架构)中,我当前的 Firebase 身份验证和实时数据库 (RTDB) 实现。而不是将 AuthStateListener 逻辑放在我的 MainActivity View 类中。我把它放在 Presenter 类中。 Presenter 类附加或分离监听器以响应视图生命周期(onResume 调用在presenter 中附加监听器,onPause 调用在presenter 中分离监听器)。
问题:在设备变为非活动状态(可能服务器关闭连接)后,再次变为活动状态。用户仍处于登录状态(预期行为),但出乎意料的是,已登录用户无法再访问 Firebase RTDB,但 RTDB 并未引发任何读/写权限被拒绝错误。从那一刻起,任何数据库读/写操作都将不起作用,从 Firebase 控制台确认。
出现此问题时,log cat 反复显示以下警告,似乎是一种退避登录尝试策略?
12-10 14:09:23.671 13076-13271/appname W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
12-10 14:09:27.191 13076-13271/ appname W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
12-10 14:09:28.182 13076-13271/ appname W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
12-10 14:09:29.659 13076-13271/ appname W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
如果用户退出,然后重新登录并再次激活,该问题将得到解决。当用户处于活动状态时,任何新的读/写操作都会执行,但之前的操作不会持久化或重试。
我使用的相关版本是
// Firebase
implementation "com.firebaseui:firebase-ui-auth:3.1.0"
implementation "com.google.firebase:firebase-database:11.6.2"
implementation "com.google.firebase:firebase-auth:11.6.2"
对于在 Android 应用的 MVP 结构中使用数据库实现 Firebase 身份验证,是否有任何最佳实践信息?
【问题讨论】:
-
在
set()或update()调用中是否有侦听器来检查失败并记录异常消息?或者您是否仅通过 Firebase 控制台数据库视图中没有更改来判断失败。 -
你能弄清楚为什么会这样吗?我遇到了同样的问题。
标签: android firebase firebase-realtime-database firebase-authentication