开发者

Use application or activity context in CookieSyncManager.createInstance

开发者 https://www.devze.com 2023-04-08 06:00 出处:网络
Is it a good idea to use application context instead of activity context in CookieSyncManager.createInstance() call?

Is it a good idea to use application context instead of activity context in CookieSyncManager.createInstance() call?

CookieSyncManager.createInstance(activity.getApplicationContext());

In Facebook's SDK, it uses activity context, which I think will cause memory leak:

CookieSyncManager.createInstance(activity);

So I decided to change it to CookieSyncManager.createInstance(activity.getApplicationContext());

Is there any problem of using application context in this case?

Thank开发者_StackOverflow社区s.


Old question, but I was just looking for the same thing.

Turns out it doesn't matter what Context you provide it in createInstance() because internally it just takes the provided context and calls getApplicationContext() on it. So either way it will end up using the application-context. Here's the source code.

I was curious about this because I wasn't sure if the CookieSyncManager class would sync/save all cookies in the entire App, or just those in the Activity that created it (if you only provided an activity-context instead of application-context). But even after knowing it's using the application-context internally, I'm still not sure about this.

I really wish the documentation would be more clear about what context-level they want/expect.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号