使用离线和在线方式查找我的应用程序。服务运行15分钟的间隔时间。自动获取数据以更新application.so,我正在使用后台服务调用api。有时仍在运行的服务我的应用程序崩溃了,我附加了完整的代码。请提供一些解决方案,为什么我的应用程序不会崩溃。
public class OdooResult extends TreeMap<String, Object> {
public String getString(String key) {
if (isValidValue(key)) {
return get(key).toString();
}
return null;
}
public Boolean getBoolean(String key) {
if (isValidValue(key)) {
return Boolean.valueOf(getString(key));
}
return false;
}
public int getInt(String key) {
if (isValidValue(key)) {
return getFloat(key).intValue();
}
return -1;
}
public Float getFloat(String key) {
if (isValidValue(key)) {
return Float.valueOf(getString(key));
}
return 0F;
}
public OdooResult getData(String key) {
if (isValidValue(key)) {
OdooResult data = new OdooResult();
data.putAll((LinkedTreeMap) get(key));
return data;
}
return null;
}
@SuppressWarnings("unchecked")
public <T> ArrayList<T> getArray(String key) {
if (isValidValue(key)) {
return (ArrayList<T>) get(key);
}
return new ArrayList<>();
}
public OdooRecord[] getRecords() {
Object data = null;
if (isValidValue("records")) {
data = get("records");
}
if (isValidValue("result") && get("result") instanceof ArrayList) {
data = get("result");
}
if (data != null) {
Gson gson = new Gson();
String recordsJSON = gson.toJson(data);
return gson.fromJson(recordsJSON, OdooRecord[].class);
}
return new OdooRecord[]{};
}
protected boolean isValidValue(String key) {
return get(key) != null;
}
}
{
"jsonrpc":"2.0", "method":"call", "params":{
"model":"plantation.offers", "fields":[
"name", "season_id", "section_id", "ryot_name_id", "plant_type_id", "crop_type_id", "offered_area", "plantation_status_id", "state"],
"domain":[],"context":{
"lang":"en_US", "tz":false, "uid":382, "params":{
"action":302
},"bin_size":true
},"offset":0, "limit":80, "sort":""
},"id":437595789
}