如标题所示。获取 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));*/
}
});
}
摇篮:
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'