当前位置: 首页 > 知识库问答 >
问题:

当使用mvvm实现初始屏幕时,会出现此错误

施同
2023-03-14
public class SplashActivtiy extends AppCompatActivity {

    private final static int MSG_CONTINUE = 1234;
    private final static long DELAY = 2000;
    private static final String TAG = SplashActivtiy.class.getSimpleName();
    private SplashViewModel splashViewModel;
    private LifecycleRegistry mLifecycleRegistry;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_activtiy);

       // FirebaseApp.initializeApp(this);

        splashViewModel = ViewModelProviders.of(this).get(SplashViewModel.class);

        splashViewModel.retrieveRemoteConfig(SplashActivtiy.this);

        mHandler.sendEmptyMessageDelayed(MSG_CONTINUE, DELAY);
    }
    @Override
    protected void onDestroy() {
        mHandler.removeMessages(MSG_CONTINUE);
        super.onDestroy();
    }


    private void _continue() {
        startActivity(new Intent(this, Swipe.class));

        finish();
    }

    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case MSG_CONTINUE:
                    _continue();
                    break;
            }
        }
    };

}
public class SplashViewModel extends ViewModel {

    private static final String TAG = SplashViewModel.class.getSimpleName();
    FirebaseRemoteConfig mFirebaseRemoteConfig;

    public void retrieveRemoteConfig(Context context) {
        Log.d(TAG, "retrieveRemoteConfig: ");
        FirebaseApp.initializeApp(context);

        mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();


        mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);

        // cacheExpirationSeconds is set to cacheExpiration here, indicating the next fetch request
        // will use fetch data from the Remote Config service, rather than cached parameter values,
        // if cached parameter values are more than cacheExpiration seconds old.
        // See Best Practices in the README for more information.

        final FirebaseRemoteConfig finalMFirebaseRemoteConfig = mFirebaseRemoteConfig;
        mFirebaseRemoteConfig.fetch()
                .addOnCompleteListener((Executor) this, new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        Log.d(TAG, "onComplete: ");
                        if (task.isSuccessful()) {
                            Log.d(TAG, "onComplete: Remote config fetched successfully");
                            //  Toast.makeText(SplashActivity.this, "Fetch Succeeded",Toast.LENGTH_SHORT).show();
                            // After config data is successfully fetched, it must be activated before newly fetched
                            // values are returned.
                            finalMFirebaseRemoteConfig.activateFetched();
                        } else {
                            //  Toast.makeText(SplashActivity.this, "Fetch Failed",Toast.LENGTH_SHORT).show();
                            Log.e(TAG, "onComplete: Remote config fetching unsuccessful " + task.getException());
                        }
                    }
                });
    }
}

共有1个答案

戚建德
2023-03-14

使用此.AddOnCompleteListener(上下文,新建OnCompleteListener ()

而不是.addoncompleteListener((Executor)this,而是new oncompleteListener ()

示例代码

final FirebaseRemoteConfig finalMFirebaseRemoteConfig = mFirebaseRemoteConfig;
    mFirebaseRemoteConfig.fetch()
            .addOnCompleteListener(context, new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    Log.d(TAG, "onComplete: ");
                    if (task.isSuccessful()) {
                        Log.d(TAG, "onComplete: Remote config fetched successfully");
                        //  Toast.makeText(SplashActivity.this, "Fetch Succeeded",Toast.LENGTH_SHORT).show();
                        // After config data is successfully fetched, it must be activated before newly fetched
                        // values are returned.
                        finalMFirebaseRemoteConfig.activateFetched();
                    } else {
                        //  Toast.makeText(SplashActivity.this, "Fetch Failed",Toast.LENGTH_SHORT).show();
                        Log.e(TAG, "onComplete: Remote config fetching unsuccessful " + task.getException());
                    }
                }
            });
 类似资料:
  • 我正在尝试在我的手机上部署我新创建的Ionic 3应用程序(我使用的是64位Windows 10),但在运行后抛出错误: 我已经安装了Android Studio。我添加了一个系统变量_JAVA_OPTIONS,其值为-Xmx512M。我还添加了值为-Xmx2048M的系统变量GRADLE_OPTS 否则我有: 为什么还会出现这个错误?

  • 我正试着通过这样做来初始化amplify 在Android项目中。不知何故,每次安装失败时,都会出现以下stacktrace: ⠹ 正在云中初始化项目。。。创建CloudFormation堆栈时出错✖ 根堆栈创建失败init失败{InvalidClientTokenId:请求中包含的安全令牌无效。在请求时出现extractError(/usr/local/lib/node_modules/@aws

  • 我们重新启动集群上的dastanodes 我们在ambari集群中有15台数据节点机器,而每个数据节点机器都有128G RAM 版本- ( HDP - 2.6.4和安巴里版本2.6.1) 但是,由于以下错误,datanode无法启动 这很奇怪dtnode_heapsize因为 8G ( 数据节点最大 Java 堆大小 = 8G ),从日志中我们也可以看到 所以我们不明白这是怎么回事 dose-与D

  • 我试图在循环中初始化数组C,但它给出了错误: C是类ipdata的数组,我已经声明了它,并试图在循环中初始化它。 有什么问题吗?它表示:无法访问cluster_anlysis类型的封闭实例。必须使用cluster_anlysis类型的封闭实例限定分配(例如,x.new A(),其中x是cluster_anlysis的实例)。

  • 当我试图创建一个新的空项目(或任何其他类型的项目)时,我在IntelliJ IDEA版本2017.3.5中得到错误int the title。到目前为止,我所做的是: > 从以下网址下载社区版本(不含jdk)https://www.jetbrains.com/idea/download/download-thanks.html?platform=linuxwithoutjdk&code=iic 将

  • 问题内容: 我正在执行以下AJAX调用: 而且没有收到预期的警报消息。相反,Firebug说我收到“未实现501”。 为什么?我需要怎么做才能解决此问题? 如果我转到Firebug中与AJAX调用相对应的URL,则会下载一个JSON文件,其中包含预期的数据。 我注意到的一件事是,萤火虫说的是OPTIONS而不是GET: 替代文字http://grab.by/grabs/b1a13d92a4fc69