androidperformancehttpsandroidhttpclient

Android - Track down why app using so much data


I am currently having an issue with my app using a lot of mobile data and I am not 100% sure why as the typical request is just JSON sent/received data and typically very small (IE sending username/password for login). Some users are reporting up to 5 GB worth of data used per month. The typical request I have seen is around 1 MB and that is only triggered once per day and the highest I have seen is 3 MB (happens once ever to download additional content). I have used the following below before and after all my AsyncHttpClient request and haven't found anything that would make it use that much data as most are less than 0.01 MB.

long bytes = TrafficStats.getUidRxBytes(applicationUID) + TrafficStats.getUidTxBytes(applicationUID);

I have tried using the profiler in android studio as well, but nothing really spikes over 100kb unless it is a direct network call (when it is supposed to). The only library functions that might use data are from Firebase and Google. Is there a better way to track this issue down?


Solution

  • After changing to volley, the easiest solution I have found to go with is to use stetho to monitor my network request directly from my browser.

    Add stetho to your build

    implementation 'com.facebook.stetho:stetho:1.5.1'
    implementation 'com.facebook.stetho:stetho-js-rhino:1.5.1'
    implementation 'com.github.darshan-kapasi:StethoForVolley:1.2.1' <~ for volley request
    

    Change the following volley request from

    RequestQueue queue = Volley.newRequestQueue(context);
    

    to

    RequestQueue queue = Volley.newRequestQueue(context, new StethoVolleyHurlStack());
    

    Initialize on main activity

    Stetho.initializeWithDefaults(this);    
    

    On your development machine, connect your phone then open chrome://inspect/ and run your app. You should see it show up under devices, click the inspect panel and you can monitor the network request that you selected.

    Resource links

    Stetho Github Repo

    Stetho Volley Github Repo