Android studio say static field will leak contexts

可紊 提交于 2019-12-13 16:13:09

问题


Here is a similar question but I think it is not identical

And I read Setting up request queue tutorial here

In this page they write the following code

public class MySingleton {
   private static Context mCtx;

And I wrote same code in my project

public class VolleySingleton {
  private static Context mContext;

Android studio say “Do not place Android context classes in static fields; this is a memory leak”.
What does it mean? And why dos the official android developer website use such kind of code?


回答1:


try this? `

class VolleySingleton {
    @SuppressLint("StaticFieldLeak")
    private static Context mContext;
}`


来源:https://stackoverflow.com/questions/48127346/android-studio-say-static-field-will-leak-contexts

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