I'm trying to use the value initialized on onPostExecute(...) in other methods, but when I call the value from another method, or another class, the value is returned as null. Presumably because the function grabs the value BEFORE it finishes loading. I tried using a do-while using boolean checks to wait for the value to finish loading (ex. do(initialize) while(!isDoneLoading)), but I get an infinite loop. The only things I have found online have said to use the postExecute to update UI components, but I need that value to grab more information from url responses!
public class StaticData{
private String mMostRecentVersion;
private void setMostRecentVersions(URL url){
...
...
...
new AsyncTask<URL, Void, JSONArray>() {
@Override
protected JSONArray doInBackground(URL... params) {
return loadJSON(params[0]);
}
@Override
protected void onPostExecute(JSONArray array){
try {
mMostRecentVersion = array.get(0).toString();//THIS IS THE VALUE I WANT
Log.d("MyApp", "Recent Version: " + mMostRecentVersion);
} catch (JSONException e) {
e.printStackTrace();
}
}
}.execute(url);
}
}
The Log.d on the onPostExecute method returns the value I need in its correct form. The issue is that calling this value from other methods returns null.