4

我的应用最近开始出现很多 CookieSyncManager 异常:

java.lang.IllegalStateException: CookieSyncManager::createInstance() 
    needs to be called before CookieSyncManager::getInstance()
at android.webkit.CookieSyncManager.getInstance(CookieSyncManager.java:81)
at android.webkit.CookieManager$2.run(CookieManager.java:532)
at java.lang.Thread.run(Thread.java:1096)

从堆栈跟踪中可以清楚地看到错误,但它的来源不是(这是来自 Play 商店报告)。附加到堆栈跟踪的用户消息表明它发生在我使用 facebook SDK 的地方,并且它确实使用了 CookieSyncManager:

// From Facebook.java
private void startDialogAuth(Activity activity, String[] permissions) {
    ...
    CookieSyncManager.createInstance(activity); // <-- here
    dialog(activity, LOGIN, params, new DialogListener() {
        public void onComplete(Bundle values) {
            CookieSyncManager.getInstance().sync(); // <-- here
            ...

https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/android/Facebook.java#L342

这对我来说看起来不错,但是上面的用法有什么问题吗?我无法在我的任何测试设备上重现错误,也许存在实施差异?

谢谢

4

2 回答 2

1

它应该像例外说:

public void onComplete(Bundle values) {
   CookieSyncManager.createInstance( activity );    // <-- this line was missing
   CookieSyncManager.getInstance().sync();
   ...
于 2012-12-05T15:03:24.997 回答
0

根据android文档

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CookieSyncManager.createInstance(MainActivity.this);
    CookieSyncManager.getInstance().startSync();
}
public void onReume(){
    super.onResume();
    CookieSyncManager.getInstance().stopSync();
}
public void onPause(){
    super.onPause();
    CookieSyncManager.getInstance().sync();
}
于 2014-10-15T12:45:26.817 回答