理想情况下我想实施
方法级同步,其中整个方法每1分钟同步
不
块级同步,其中只有一组语句被同步
但我不知道为什么我的新runnable处理程序在设定的时间间隔执行该方法。它会一次又一次地解析未更改的json数据,并以冗余方式填充我的listview。
如何实现一个处理程序,该处理程序只解析从前60秒更改/更新的json中的数据,而不重复列表视图上的数据?
private class MyAsyncTask extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(RegionListActivity.this);
dialog.setMessage("Please wait..");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.show();
}
@Override
protected String doInBackground(Void... params) {
String url_structure = GlobalData.MAIN_URL + sessionId
+ "/user_session/?sections=app-basic&company_id="
+ companyId;
String response_structure = CallWebService
.getResponseOfUrl(url_structure);
parseRegionList(response_structure);
String url_unit = GlobalData.MAIN_URL + sessionId
+ "/reporting/system/unit_status/?sections&company_id="
+ companyId;
String response_unit = CallWebService.getResponseOfUrl(url_unit);
parseUnitStatus(response_unit);
return null;
}
@SuppressWarnings("null")
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
dialog.dismiss();
if (!alRegions.isEmpty() && !alParents.isEmpty()) {
expandableAdapter = new ExpandableListAdapter(
RegionListActivity.this, alParents);
lvExpandableRL.setAdapter(expandableAdapter);
GlobalData.alAssetsGlobal = hashMapAssets;
GlobalData.alComponetsGlobal = hashMapComponents;
}
else {
lvExpandableRL.setVisibility(View.GONE);
tvNoRecordsRL.setVisibility(View.VISIBLE);
}
tvCompanyNameRL.setText(GlobalData.COMPANY_NAME);
tvActiveAlarmsRL.setText(GlobalData.ACTIVE_ALARMS);
tvUnitsOfflineRL.setText(GlobalData.OFFLINE_COUNT);
/*
* try { if(alUnitNumber.size()>0 && alUnitNumber != null) {
* al_unit_snumber=alUnitNumber;
* lvUnitsOffline.setVisibility(View.VISIBLE); adapter= new
* UnitListAdapter(RegionListActivity.this, alUnitNumber);
* lvUnitsOffline.setAdapter(adapter); } else {
* lvUnitsOffline.setVisibility(View.GONE);
* tvNoRecordsUnitListOffline.setVisibility(View.VISIBLE); } } catch
* (Exception e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*
* if(alUnitStatus.size()>0 && alUnitStatus != null)
*
* alUnitStatus=(ArrayList<DataUnits>)getArguments()
* .getSerializable(WebElement.RECORDS); if(alUnitStatus.size()>0 &&
* alUnitStatus != null) { al_unit_snumber=alUnitNumber;
* lvUnitsOffline.setVisibility(View.VISIBLE); adapter= new
* UnitListAdapter(RegionListActivity.this, alUnitStatus);
* lvUnitsOffline.setAdapter(adapter); } else {
* lvUnitsOffline.setVisibility(View.GONE);
* tvNoRecordsUnitListOffline.setVisibility(View.VISIBLE); }
*/
}
new Handler().postDelayed(new Runnable() {
public void run() {
// call JSON methods here
new MyAsyncTask().execute();
}
}, 60000);
}