android - Firebase Remoteconfig 获取崩溃 Android 应用程序

标签 android firebase firebase-remote-config

如题。获取 Firebase 配置会使应用程序崩溃。在同一个应用程序中,Firebase 数据库和崩溃报告完美运行。

错误信息:

Caused by: java.lang.IllegalStateException: Activity has been destroyed
                  at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1854)
                  at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:643)
                  at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:608)
                  at com.google.android.gms.internal.zzrn.zza(Unknown Source)
                  at com.google.android.gms.internal.zzra.zzc(Unknown Source)
                  at com.google.android.gms.internal.zzra.zzs(Unknown Source)
                  at com.google.android.gms.tasks.zzh$zza.zzv(Unknown Source)
                  at com.google.android.gms.tasks.zzh.addOnCompleteListener(Unknown Source)
                  at com.foo.foo.Common.DatabaseManager.getRemoteConfig(DatabaseManager.java:85)
                  at

我不明白这是怎么回事。相关代码:

private void getRemoteConfig() {
    remoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    remoteConfig.setConfigSettings(configSettings);
    remoteConfig.setDefaults(R.xml.remote_config_defaults);
    long cacheExpiration = 3600;

    //expire the cache immediately for development mode.
    if (remoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
        cacheExpiration = 0;
    }

    remoteConfig.fetch(cacheExpiration).addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                remoteConfig.activateFetched();
            }
            //LocalBroadcastManager.getInstance(null).sendBroadcast(new Intent(AppConstants.kNotificationonRemoteSettingsLoaded));*/
        }


    });
}

Gradle :

compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'
compile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.android.support:appcompat-v7:25+'
compile 'com.google.android.gms:play-services-maps:9.6.1'

apply plugin: 'com.google.gms.google-services'

最佳答案

我遇到了同样的问题。问题是我在 Super.oncreate() 之前使用了 firebase 远程配置获取。检查调用 getRemoteConfig() 过程的位置!

关于android - Firebase Remoteconfig 获取崩溃 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41358984/

相关文章:

android - 在android中滚动Textview

android - 为什么建议将扩展 Room Database 的类抽象化?

java - 为首选项编写测试,访问首选项时不断获取 `android.content.res.Resources$NotFoundException`

firebase - Firestore : restricting child/field access with security rules

typescript - Cloud Functions auth onCreate 触发器将用户添加到 Firestore

ios - Swift - 如何为 FB Auth 处理来自 FIRUserInfo 的数据?

ios - 在 iOS Firebase 远程配置中的应用程序启动过程中,是否会获取但未应用的值?

android - Firebase 远程配置 - 检查值是否存在

android - 模拟 FirebaseRemoteConfig getBoolean()

android - 在警报对话框中显示进度条