我打开这个页面并与服务器同步,并显示从服务器返回的记录和数据。我想提高我的应用程序的性能。我是新的缓存内存,所以请帮助我或给我一些其他的想法,使我的应用程序更快。
class CreateNewProduct extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Categry.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_search, "GET", params);
Log.d("Search idioms: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
idioms = json.getJSONArray(TAG_IDIOMS);
// looping through All Products
for (int i = 0; i < idioms.length(); i++) {
JSONObject c = idioms.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_ID);
String entry = c.getString(TAG_ENTRY);
String meaning = c.getString(TAG_MEANING);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, id);
map.put(TAG_ENTRY, entry);
map.put(TAG_MEANING, meaning);
// adding HashList to ArrayList
idiomsList.add(map);
}
} else {
// no idioms found
//do something
//tv1.setVisibility(View.VISIBLE);
//Toast.makeText(getBaseContext(), "NO data found", Toast.LENGTH_LONG).show();
}
}
/*catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
Toast.makeText(getBaseContext(), "NO data found", Toast.LENGTH_LONG).show();
}*/
catch (JSONException e) {
Log.e("log_tag", "Error in http connection" + e.toString());
Toast.makeText(getBaseContext(), "NO data found", Toast.LENGTH_LONG).show();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
Categry.this, idiomsList,
R.layout.activity_list_child, new String[]{TAG_ID, TAG_ENTRY, TAG_MEANING},
new int[]{R.id.id, R.id.entry, R.id.meaning});
lv.setAdapter(adapter);
}
});
}
}
@Override
public void onBackPressed() {
Intent intent = new Intent(getBaseContext(), homescreen.class);
startActivity(intent);
finish();
// overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_categry, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
Intent i = new Intent(getBaseContext(), qrcode.class);
startActivity(i);
return true;
case android.R.id.home:
Intent intent = new Intent(getBaseContext(), homescreen.class);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}发布于 2015-07-27 07:34:16
如果您完全和完整地处理json,并使应用程序更加流畅,就可以使用称为改造的库,它非常简单,很容易与您的json集成,那么您可以将它存储为一个json文件,以便进行脱机访问。
https://stackoverflow.com/questions/31647182
复制相似问题