小编Gid*_*wer的帖子

更新到新SDK后,与Firebase数据库失去联系

更新我的项目Firebase SDK后,我注意到我的应用程序经常失去与firebase数据库的连接.断开连接所需的时间从几分钟到一个多小时不等.断开连接后,在我注销或清除应用数据之前,应用不会重新连接.

在我失去连接之前,日志中的条目表明我的身份验证令已过期:

PersistentConnection:pc_0 - 撤销身份验证令牌:expired_token(身份验证令牌已过期.)

仅供参考,我使用Twitter和Facebook进行身份验证,并且没有使用以前的Firebase SDK遇到此类问题.

我创建了一个新项目(使用简单的身份验证和实时数据库)来查看问题是否仍然存在并且确实存在.我附上了这个新项目的片段:

的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.sample.gideon.test"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.12.0'
    compile 'com.google.firebase:firebase-database:9.0.0'
    compile 'com.google.firebase:firebase-auth:9.0.0'
    compile 'com.android.support:design:23.4.0'
}

apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

验证活动遵循firebase facebook登录指南,该指南确实成功登录用户并将其发送到MainActivity,然后MainActivity使用以下代码监视数据库连接:

主要活动

    DatabaseReference connectedRef …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-authentication firebase-realtime-database

10
推荐指数
1
解决办法
1867
查看次数