简体   繁体   English

你应该在 addOnCompleteListener 里面写什么?

[英]What are you supposed to write inside addOnCompleteListener?

I'm currently trying to use firebase remote in my android project by following [docs][1] and I'm at the point where I have to fetch my values but it keeps giving me an error when I'm literally copy pasting the code from the docs (see code below).我目前正在尝试按照 [docs][1] 在我的 android 项目中使用 firebase remote,我现在必须获取我的值,但是当我从字面上复制粘贴时,它一直给我一个错误来自文档的代码(见下面的代码)。 It keeps saying "cannot resolve method addOnCompleteListener" but since I don't really understand what's supposed to be written inside the function, I can't seem to fix the problem.它一直说“无法解析方法 addOnCompleteListener”,但由于我真的不明白函数内部应该写什么,我似乎无法解决这个问题。

private void fetchConfig() {
      mFirebaseRemoteConfig.fetchAndActivate()
            .addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
                @Override
                public void onComplete(@NonNull Task<Boolean> task) {
                    if (task.isSuccessful()) {
                        boolean updated = task.getResult();
                        Log.d(TAG, "Config params updated: " + updated);
                        Toast.makeText(MainActivity.this, "Fetch and activate succeeded",
                                Toast.LENGTH_SHORT).show();

                    } else {
                        Toast.makeText(MainActivity.this, "Fetch failed",
                                Toast.LENGTH_SHORT).show();
                    }
                    displayWelcomeMessage();
                }
            });
}

Also I'm currently using these dependencies in my build.gradle:此外,我目前在 build.gradle 中使用这些依赖项:

implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-config:19.0.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
implementation 'com.google.firebase:firebase-core:17.0.1'

I don't really know what versions I have to take for these dependencies, because I'm working with quite a low API level.我真的不知道我必须为这些依赖项采用什么版本,因为我正在使用相当低的 API 级别。 It's for a school assignment which had a requirement that said min api 16 so that's what I picked when creating the project.这是一个学校作业,它的要求是 min api 16 所以这是我在创建项目时选择的。 But anyway does someone know what the problem could be?但无论如何有人知道问题可能是什么吗? Or can someone explain me what this part is supposed to do for my firebase config?或者有人可以向我解释这部分应该为我的 firebase 配置做什么?

Sometimes the problem is with the Firebase implementation version, try changing to this versions.有时问题出在 Firebase 实现版本上,请尝试更改为此版本。

implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-config:19.1.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
implementation 'com.google.firebase:firebase-core:17.2.1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM