首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android中将JSON数据存储在移动缓存内存中

在Android中将JSON数据存储在移动缓存内存中
EN

Stack Overflow用户
提问于 2015-07-27 07:25:39
回答 1查看 1.7K关注 0票数 0

我打开这个页面并与服务器同步,并显示从服务器返回的记录和数据。我想提高我的应用程序的性能。我是新的缓存内存,所以请帮助我或给我一些其他的想法,使我的应用程序更快。

代码语言:javascript
复制
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);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-07-27 07:34:16

如果您完全和完整地处理json,并使应用程序更加流畅,就可以使用称为改造的库,它非常简单,很容易与您的json集成,那么您可以将它存储为一个json文件,以便进行脱机访问。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31647182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档