在 CookieSyncManager.createInstance 中使用应用程序或活动上下文
在 CookieSyncManager.createInstance() 调用中使用应用程序上下文而不是活动上下文是一个好主意吗?
CookieSyncManager.createInstance(activity.getApplicationContext());
在Facebook的SDK中,它使用了activity context,我认为这会导致内存泄漏:
CookieSyncManager.createInstance(activity);
所以我决定将其更改为CookieSyncManager.createInstance(activity.getApplicationContext());
在这种情况下使用应用程序上下文有什么问题吗?
谢谢。
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?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老问题,但我只是在寻找同样的东西。
事实证明,您在
createInstance()
中提供什么Context
并不重要,因为在内部它只需要提供的context
并调用getApplicationContext() 就可以了。因此,无论哪种方式,它最终都会使用应用程序上下文。这是 源代码。
我对此很好奇,因为我不确定
CookieSyncManager
类是否会同步/保存整个应用程序中的所有 cookie,或者只是创建它的Activity
中的那些(如果您只提供了活动上下文而不是应用程序上下文)。但即使知道它在内部使用应用程序上下文,我仍然不确定这一点。我真的希望文档能够更清楚地说明他们想要/期望的上下文级别。
Old question, but I was just looking for the same thing.
Turns out it doesn't matter what
Context
you provide it increateInstance()
because internally it just takes the providedcontext
and callsgetApplicationContext()
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 theActivity
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.