I’m trying to pull multiple variables at once on an Android app. This works but is there better approach to this?
@Override
public Map<String, String> callApi(@NonNull ParticleCloud ParticleCloud) throws ParticleCloudException, IOException {
ParticleDevice device = ParticleCloud.getDevice(getIntent().getStringExtra(ARG_DEVICEID));
Map<String, String> returnVals = new ArrayMap<>();
String value;
for (String var : new String[]{"V1", "V2", "V3", "V4", "V5"}) {
try {
value = device.getStringVariable(var);
returnVals.put(var, value);
} catch (ParticleDevice.VariableDoesNotExistException e) {
Toaster.l(VariablesActivity.this, "Error reading variable " + var);
}
}
return returnVals;
}