Somehow, I can’t get this done. This is all what I tried till now:
-
Main:
private String myState; public String getState() { return myState; } public void setState(String s) { myState = s; }Async:
Main appState = ((Main)getApplicationContext()); String state = appState.getState();Error:
No enclosing instance of the type Main is accessible in scope -
Tried with Helper(Globals) class.
public class Globals extends Application{ private String test= "1"; }Main:
private Globals mGlobals; mGlobals = new Globals(); mGlobals.test = "2"; //Do Async thingAsync:
private Globals mGlobals; mGlobals = new Globals(); print mGlobals.test; // (result is 1, should be 2) -
Also something else, but don’t remember good.
Tried alot of things (backspace and del buttons are over-used :p )
But I can’t get everything working.Async class doesn’t have an activity.
Code pasted: http://pastebin.com/ikcsdL1p
Instead of trying to get Application Context , try to pass Context directly in AsyncTask Constructor. as @Mohd Mufiz already mentioned in his Answer.