I am writing an android application recording sensor data. Trying to save these data to json File, but the json array turns out to repeat the item of the array with the most recent measurement.
private JSONObject mSensorState = new JSONObject();
private JSONArray mSensorBuffArray = new JSONArray();
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
...
mSensorState.put("HR",HR_data);
mSensorState.put("Step",Step_Data);
mSensorBuffArray.put(mSensorState);
Log.d(TAG,"JSON "+ mSensorState.toString());
Log.d(TAG,"JSON "+ mSensorBuffArray.toString());
}
The data for current state 'mSensorState' displace correctly as an json object. updated as expected
JSON {"HR":"95","Step":"10328"}
JSON {"HR":"96","Step":"10328"}
JSON {"HR":"98","Step":"10328"}
But the array doesn't. It was shown as an array of most recent measurement.
JSON [{"HR":"98","Step":"10328"},{"HR":"98","Step":"10328"},{"HR":"98","Step":"10328"},