如何在使用来自服务器的json提要时快速创建我的android应用程序
我已经在电子商务网站(magento 2)上生成了一个应用程序,而我正在尝试启动我的应用程序,因为我的服务器中有很多产品,所以它的处理速度非常慢。在使用JSON提要时,是否有任何可能的方法加快我使用异步任务的速度。。请告诉我任何可能的方法 我的任务之一是异步任务编码:如何在使用来自服务器的json提要时快速创建我的android应用程序,android,json,magento,android-asynctask,Android,Json,Magento,Android Asynctask,我已经在电子商务网站(magento 2)上生成了一个应用程序,而我正在尝试启动我的应用程序,因为我的服务器中有很多产品,所以它的处理速度非常慢。在使用JSON提要时,是否有任何可能的方法加快我使用异步任务的速度。。请告诉我任何可能的方法 我的任务之一是异步任务编码: private class GetProduct extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute
private class GetProduct extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
dialog_pro = new ProgressDialog(Healthy_Cat.this);
dialog_pro.setMessage("Please wait...");
dialog_pro.setCancelable(false);
dialog_pro.show();
}
@Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
String jsonStr = sh.makeServiceCall(url);
if (jsonStr != null) {
try {
JSONArray items = new JSONArray(jsonStr);
for (int i = 0; i < items.length(); i++) {
JSONObject c = items.getJSONObject(i);
pro_name = c.getString("name");
String price = c.getString("price");
JSONArray array = c.getJSONArray("custom_attributes");
for (int k = 0; k < array.length(); k++) {
JSONObject jb = array.getJSONObject(k);
String attr = jb.getString("attribute_code");
if (attr.equalsIgnoreCase("special_price")) {
splprice = jb.getString("value");
}
}
String sku = c.getString("sku");
JSONArray media = c.getJSONArray("media_gallery_entries");
for(int k = 0; k < media.length(); k++) {
JSONObject jb = media.getJSONObject(k);
String imageURL = BaseURL_Helper.MediaBase +jb.getString("file");
media_image = imageURL;
// tmp hash map for single contact
Beanclass dataSet = new Beanclass();
dataSet.setTitle(pro_name);
dataSet.setImage(imageURL);
dataSet.setPrice(price);
dataSet.setSPLPrice(splprice);
dataSet.setSku(sku);
list.add(dataSet);
BeanclassList data = new BeanclassList();
data.setTitle(pro_name);
data.setImage(imageURL);
data.setSku(sku);
data.setSPLPrice(splprice);
data.setPrice(price);
listbean.add(data);
}
}
}catch (final JSONException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
no_list.setVisibility(View.VISIBLE);
}
});
}
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"May be Network error!!",
Toast.LENGTH_LONG)
.show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
/**
* Updating parsed JSON data into ListView
* */
if (dialog_pro.isShowing())
dialog_pro.dismiss();
mAdapter = new GridviewAdapter(Healthy_Cat.this,list);
gridlist.setAdapter(mAdapter);
Listadapter = new ListviewAdapter(Healthy_Cat.this,listbean);
listview_pro.setAdapter(Listadapter);
}
}
私有类GetProduct扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
//显示进度对话框
dialog\u pro=新进度对话框(健康的\u Cat.this);
对话框设置消息(“请稍候…”);
对话框专业设置可取消(错误);
dialog_pro.show();
}
@凌驾
受保护的Void doInBackground(Void…arg0){
HttpHandler sh=新的HttpHandler();
字符串jsonStr=sh.makeServiceCall(url);
if(jsonStr!=null){
试一试{
JSONArray项目=新JSONArray(jsonStr);
对于(int i=0;i
先谢谢你 与改装相比,Asyntask性能速度太低
因此,对于电子商务应用程序,您必须使用改型。与改型相比,Asyntask性能速度太低
因此,对于电子商务应用程序,您必须使用改型。代码中几乎没有需要更新的内容
代码中几乎没有需要更新的内容
你可以做几件事。首先,在更新视图之前,不必解析整个json。
但实际上你自己也在陈述问题,那就是你有太多的数据。这不仅是一个编程问题,也是一个用户体验问题,太多的数据令人困惑,尤其是在移动设备上。
我的建议是把你的数据分成不同的类别。当应用程序启动时,只下载要显示的类别列表。用户选择一个类别后,您就可以下载该类别的数据