Is it a bad practice to hold application Context instance?

白昼怎懂夜的黑 提交于 2019-11-30 19:00:40

is it a bad practice to save the application Context in my Application class?

It is a code smell.

Can it lead to a massive memory leak?

Having the static data member will not lead to a massive memory leak. Whether your over-use of the Application object will lead to a massive memory leak depends upon where and how you use it.

What are the drawbacks I'm not seeing?

Not all Contexts are created equal. Generally speaking, only use Application when you know specifically why you need the Application context, not for everything.

Dave Smith of DoubleEncore has an awesome blog post covering the differences between types of Context and when to use one over another.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!