android - Activity having static reference -


i'm working on exiting android code written else , has several memory issues. 1 issue i'm not able understand this. in main activity class has static method called getreference(). method returns reference variable called mthis. now, in oncreate method

class myactivity extends activity  {      private static myactivity mthis;          public myactivity getreference(){            return mthis;     }      public oncreate(bundle savedinstancestate){        mthis = this;      }      ... } 

now in content provider or class extending dialog class, uses static method reference context.

i'm pretty sure not correct , 1 of reason memory leak. there way current context without passing context object in every class. there application context don't think has method current context.

i can remove method , pass reference context object these classes. there other way fix this.

i'm pretty sure not correct , 1 of reason memory leak.

yes.

but there way current context without passing context object in every class.

there no "current context". please supply context method needs one. notice, example, of android sdk set way.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -