Android应用会产生大量网络流量

时间:2013-12-03 16:00:57

标签: php android json network-traffic

我正在构建一个连接到远程MySQL数据库以获取指定数据的Android应用程序。 我正在使用AsyncTask和JSON从数据库中读取,AsyncTask每20秒执行一次。 问题是,当我测量我的应用程序的流量(上传和下载)时,它超过正常值,意味着应用程序每20秒使用大约5 kB。 这是AsyncTask的代码:

任何帮助将不胜感激。

    class NewOrders extends AsyncTask<String,Integer,Integer>{
    public Integer doInBackground(String...strings){
        int res=0;
        String today = todaysdf.format(new Date());
        String ftime = fullsdf.format(new Date());

        listOrders.add(new BasicNameValuePair("action", "myRequests"));
        listOrders.add(new BasicNameValuePair("taxiid", idCab));
        listOrders.add(new BasicNameValuePair("driverid", idDriver));
        listOrders.add(new BasicNameValuePair("devid", idDevice));
        listOrders.add(new BasicNameValuePair("date", today));
        listOrders.add(new BasicNameValuePair("time", ftime));
        try {
            postOrders.setEntity(new UrlEncodedFormEntity(listOrders));
            responseOrders = clientOrders.execute(postOrders);
            entityOrders = responseOrders.getEntity();
            resultOrders = EntityUtils.toString(entityOrders,"UTF-8");
            jarrayOrders = new JSONArray(resultOrders);
            if (jarrayOrders.length() > 0) {
                res = 1;
            }
            else {
                jarrayOrders = null;
            }
        } catch (Exception e) {e.printStackTrace();}
        return res;
    }

    public void onPostExecute(Integer result){
        if(result==1){
            playNotification();
            notifyNewOrder();
        }
    }
}

0 个答案:

没有答案
相关问题