本文介绍了CookieSyncManager :: createInstance建立()需要CookieSyncManager ::之前的getInstance被称为()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误消息是pretty的明确的:

This error message is pretty clear:

CookieSyncManager :: createInstance建立()  需要之前调用  CookieSyncManager ::的getInstance()

不过,我只得到这个错误,因为我跟着官方文档

But I only get this error because I followed the official documentation:

要使用CookieSyncManager,主机  应用程序调用下面的  应用程序启动时:

CookieSyncManager.createInstance(context)

    

要设置同步,主机  应用程序调用

To set up for sync, the host application has to call

CookieSyncManager.getInstance().startSync()

在Activity.onResume()

in Activity.onResume()

只有当应用程序试图恢复,而不是当它开始出现清晰的错误。

The error occurs only when the application attempts to resume, not when it starts cleanly.

所以,我也许可以解决这个问题通过移动 CookieSyncManager.createInstance(上下文) Activity.onResume()但是......不就是创建一个的问题?

So, I can probably fix that by moving CookieSyncManager.createInstance(context) to Activity.onResume() but... won't that create a new problem?

(例如,每个应用程序恢复时间忘了previous会话cookie?)

(for example, forgetting the previous session cookies every time the app resumes?)

推荐答案

我也跟着在最近的应用程序和CookieSyncMasnager是工作就好了......

I followed the official documentation in one of recent apps and CookieSyncMasnager is working just fine...

我有以下几点:

onCreate()
    CookieSyncManager.createInstance(this);

onResume()
    CookieSyncManager.getInstance().startSync();

onPause()
    CookieSyncManager.getInstance().stopSync();

我现在用的活动范围内的createInstance建立()。你做,你正在使用的情况下没有提及?

I am using the activity context in the createInstance(). You don't mention which context you're using?

您还没有提到做CookieSyncManager.getInstance()。stopSync()中的onPause()(或类似)。因此,也许你正在调用CookieSyncManager.getInstance()简历。startSync()两次,中间没有停?

You also don't mention doing a CookieSyncManager.getInstance().stopSync() in onPause() (or similar). So perhaps for a resume you are calling CookieSyncManager.getInstance().startSync() twice without an intervening stop?

这篇关于CookieSyncManager :: createInstance建立()需要CookieSyncManager ::之前的getInstance被称为()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 07:34