I have a manager class, which update json data from web, get values… The structure:
class JsonManager() {
private static JsonManager instance = null;
public static JsonManager getInstance() {
if (instance == null) {
instance = new JsonManager();
}
return instance;
}
private JSONObject data = null;
pulbic void update() {
// Download json...
String jsonResult = JsonDownloader.get();
// Create json object
data = new JSONObject(jsonResult);
Log.d("LOG", "Value in update: " + data.getBoolean("isComplete"));
}
public boolean getValue() {
boolean result = data.getBoolean("isComplete");
Log.d("LOG", "Value in getValue: " + data.getBoolean("isComplete"));
return result;
}
}
First on the server the “isComplete” value is false and if I get value after start is return with false and it’s ok. But if I change the value on the server side to true and call update and after that call getValue is come back again wtth false! But in the jsonResult arrive true value. The logs:
Start:
Value in update: false
Value in getValue: false
Refresh:
Value in update: true
Value in getValue: false
Why? Thanks
Might be because the instance of “data” object is created in update(), so might be that in getvalue() your are using another instance of data object.
make sure that you are accessing both method with same data object instance.