Android app produces a lot of network traffic

59 views Asked by At

I'm building an android app that connects to a remote MySQL database to fetch for a specified data. I'm using a AsyncTask and JSON to read from the database, the AsyncTask is executed every 20 seconds. The problem is that when I measure the traffic (upload and download ) for my app, it exceeds the normal values, means the app uses approximately 5 kB every 20 seconds. Here is the code of the AsyncTask:

Any help will be appreciated.

    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

There are 0 answers