Pro Yearly is on sale from $80 to $50! »

Reducing Mobile Data Usage in your Android Apps

Reducing Mobile Data Usage in your Android Apps

In this presentation, we take a look at the different areas in your app that you can improve mobile data usage in. Specifically Server Interactions, Images and APK Package Size.


Rebecca Franks

June 14, 2016


  1. @riggaroo Reducing Mobile Data Usage in your Apps Rebecca Franks

  2. @riggaroo Rebecca Franks Senior Android Developer & Google Developer Expert

    DVT / DStv @riggaroo
  3. @riggaroo Why should we reduce data usage? Expensive Mobile Data

  4. @riggaroo Why should we reduce data usage?

  5. @riggaroo 3 Areas to improve Images Bundled App Server Interactions

  6. @riggaroo Server Interactions

  7. @riggaroo Features of your API have a huge impact on

    performance of your app
  8. @riggaroo Offline First Design

  9. @riggaroo Every Request Counts.

  10. @riggaroo Aggregate on the Backend

  11. @riggaroo Design your API based on the usage of your

    app { "name": "Rebecca Franks”, "profileUrl": "", "followers": 50, "repositories": [ { "name": "Book Dash Android App", "id": "bookdash-android-app" }, { "name": "MVP Example", "id": "mvp-example" } ] }
  12. @riggaroo Strip unused information { login: "riggaroo", id: 9973046, avatar_url:

    "", gravatar_id: "", url: "", html_url: "", followers_url: "", following_url: "{/other_user}", gists_url: "{/gist_id}", starred_url: "{/owner}{/repo}", subscriptions_url: "", organizations_url: "", repos_url: "", events_url: "{/privacy}", received_events_url: "", type: "User", site_admin: false, name: "Rebecca Franks", company: null, blog: "", location: "Johannesburg, South Africa", email: null, hireable: null, bio: "Google Developer Expert for Android. Senior Android Developer based in South Africa. ", public_repos: 14, public_gists: 5, followers: 128, following: 13, created_at: "2014-11-27T06:32:40Z", updated_at: "2016-06-03T15:23:57Z" } { login: "riggaroo", id: 9973046, avatar_url: "", url: "", html_url: "", followers_url: "", following_url: "{/other_user}", gists_url: "{/gist_id}", starred_url: "{/owner}{/repo}", repos_url: "", type: "User", site_admin: false, name: "Rebecca Franks", blog: "", location: "Johannesburg, South Africa", bio: "Google Developer Expert for Android. Senior Android Developer based in South Africa. ", public_repos: 14, followers: 128, following: 13, }
  13. @riggaroo GZIP your Data Ensure app is requesting GZIP

  14. @riggaroo Enable HTTP Cache Cache-Control: max-stale=3600 private final OkHttpClient client;

    public CacheResponse(File cacheDirectory) throws Exception { int cacheSize = 10 * 1024 * 1024; // 10 MiB Cache cache = new Cache(cacheDirectory, cacheSize); client = new OkHttpClient.Builder() .cache(cache) .build(); }
  15. @riggaroo Keeping user’s data fresh Any new data now? And

    now? What about now? Have some data Have the same data Have the same data ☁
  16. @riggaroo Keeping user’s data fresh Give me the data Have

    some data Have the changed data ☁ Firebase Cloud Messaging Have the changed data
  17. @riggaroo Be courteous Wait for ideal conditions - WiFi +

    Battery Defer unimportant operations
  18. @riggaroo GcmNetworkManager •Schedule one-off vs. periodic tasks. •Automatic back-off and

    failure retry. •Awareness of network activity. •Awareness of device charging state. •Persistence of tasks across boot.
  19. @riggaroo Give your user options… Sync Frequency Image Quality

  20. @riggaroo Try new things Push Messaging

  21. @riggaroo Tools to monitor Data Usage

  22. @riggaroo Stetho by Facebook (Android) Allows you to use Chrome

    Developer Tools with Android Apps - Monitor requests - Edit Preferences & Databases
  23. @riggaroo Charles Proxy •HTTP Request Proxying •View Web Traffic •Throttle

    connections •Intercept Traffic •
  24. @riggaroo

  25. @riggaroo Android Network Monitor How and when your app transfers

  26. @riggaroo Emulator

  27. @riggaroo Images

  28. @riggaroo Don’t download what your users wont see.

  29. @riggaroo Don’t download large images for small areas

  30. @riggaroo Look at Device Pixel Ratio Android Low

    DPI Retina Display
  31. @riggaroo Don’t download images twice. Cache them.

  32. @riggaroo Download lower quality on slower networks.

  33. @riggaroo Image Compression Always use *SAVE FOR WEB*

  34. @riggaroo zopfliPNG ImageMagick PNGQuant PNGWolf PunyPNG Defluff TinyPNG PNGGauntlet TruePNG

  35. @riggaroo 1.2MB 183KB 201KB aaptOptions { cruncherEnabled = false }

    Custom Compression AAPT
  36. @riggaroo • VectorDrawable / ShapeDrawable • WebP (4.1 above) •

    Transparent WebP - (4.4 above) • JPEG • PNG Image Types Supported in Android
  37. @riggaroo VectorDrawable WebP JPG PNG Can the image be a

    VD? Do you support WebP? Does it need transparency? Is it simple or complex? Yes Yes Yes Simple Complex No No No How to decide what type of image to use:
  38. @riggaroo Bundled Package Size Size of your APK

  39. @riggaroo What is packaged in our APK? • App Code

    • classes.dex • Native Code (libs/ <arch>/*.so) • Resources • res/ • resources.arsc (uncompressed!) • Misc • assets/ • META-INF/ • AndroidManifest .xml .apk
  40. @riggaroo APK Analyser • Demo

  41. @riggaroo Removing Unused Code buildTypes { release { minifyEnabled true

    shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt' } Enable ProGuard + Test
  42. @riggaroo Removing Unused Code android { defaultConfig { ... resConfigs

    "en", "zu" } } Remove unused configurations 0.35MB SAVED 4MB -> 3.65MB =
  43. @riggaroo Build Variants • Split APK up • Architecture •

    Screen Size • Downside - many APKs to test android { ... splits { abi { enable true reset() include 'x86', 'armeabi-v7a', 'mips' universalApk true } } }
  44. @riggaroo ArscBlamer • resources.arsc file gets big • ArscBlamer is

    a command-line tool that can parse an Android app's resources.arsc file and extract useful, actionable information about its contents. •
  45. @riggaroo REMEMBER Every Request Counts Reduce your size of your

    app Optimise your image usage
  46. @riggaroo Thank you.

  47. @riggaroo Links • Image Compression for Android Developers- watch?v=r_LpCi6DQME

    • APK Analyser - android-studio-22-preview-new-ui.html • Network Monitor - network.html • Put your APK on a diet - • • performance-on-android-with-flatbuffers/ • tool-4ce38a24019d#.vi5zl3tjr