Best Practice:Android Connectivity for Billions-Part 1

Truth be told, It’s no top secret that Google is! oh really did i just say that?.Well, i needless tell you that Google has the Android platform — the biggest, most widely used mobile platform in the world. And to reaffirm its position, Google CEO Sundar Pichai dished out some massive numbers during his Keynote address kicking off Google I/O 2017.

As Android is the company’s biggest product, Google was proud to say that its mobile OS is now active on over 2 billion monthly active devices as of 2017. Pichai credits the milestone to the rise of smartphones across the world.

Now the big question is of what value is this statistics to android developers across the world? Well, you don’t have to figure it out, i already did!. In the next couple of weeks, i will be giving you awesome best practices that would allow you to create stunning apps that targets over 2 billion devices effortlessly.

Alright, enough of the stats, lets dive into the real stuff. Today, i am kickstarting with Android Connectivity for devices powered by android!

Android Connectivity for Devices

Over half of all users worldwide will experience your app over a 2G connection, that sounds like a sarcasm to you?trust me it’s real!. To improve their experience, you should optimize for low-speed connections and offline working by storing data, queuing requests, and handling images for optimal performance. Here i will share some tips on how to accomplish these things in no time.

1. Optimize images

There are a number of methods to make images easier to download. These include serving WebP images, dynamically sizing images, and using image-loading libraries.

  • Serve WebP images: You can serve WebP files over the network to reduce image load times and save network bandwidth of user. A WebP file is often smaller in size than its PNG and JPG counterparts, with at least the same image quality. Even using lossy settings, WebP can produce a nearly identical image to the original. Android has included lossy WebP support since Android 4.0 (API level 14: Ice Cream Sandwich) and support for lossless, transparent WebP since Android 4.2 (API level 17: Jelly Bean).
  • Dynamically size images: You can have your apps request images at the target rendering size, based on the device specification, and your server provide appropriately sized images. Doing this minimizes the data sent over the network and reduces the amount of memory needed to hold each image, resulting in improved performance and user satisfaction. User experience degrades when users have to wait for images to download. Using appropriate image sizes helps to address these issues. Consider making image size requests based on network type or network quality; this size could be smaller than the target rendering size.
  • Use image loading libraries: Your app should not fetch any image more than once. Image loading libraries such as Glide and Picasso fetch the image, cache it, and provide hooks into your Views to show placeholder images until the actual images are ready. Because images are cached, these libraries return the local copy the next time an image is requested. Image-loading libraries manage their cache, holding onto the most recent images so that your app storage doesn’t grow indefinitely. Most developers have met over the years adopt Glide and Picasso in their development, so i highly recommend.

2. Optimize networking

Another method that works well is to enhance the user experience by providing an optimal network experience. For instance, you can make your app usable offline, use GcmNetworkManager and content providers, and deduplicate network requests.

  • Make your app usable offline: In rural location and less affluent areas, it’s common for devices to lose network connectivity.As a developer, creating a useful offline state means users can interact with your app at all times. This is achievable by storing data locally, caching data, and queuing outbound requests to action when connectivity is restored. Where possible, apps shouldn’t notify users that connectivity has been lost. It’s only when the user performs an operation where connectivity is essential that the user needs to be notified.
  • Use GcmNetworkManager and content providers: If you choose to use this approach, ensure that your app stores all data on disk using a database or similar structure so that it performs optimally regardless of network conditions (for example, using SQLite and ContentProvider). Amazingly, the GCM Network Manager ( GcmNetworkManager) offers a robust mechanism to sync data with servers while content providers (ContentProvider) cache that data, combining to provide an architecture that enables a useful offline state.
  • Deduplicate network requests: An offline-first architecture initially tries to fetch data from local storage and, failing that, requests the data from the network. After being retrieved from the network, the data is cached locally for future retrieval. This helps to ensure that network requests for the same piece of data only occur once — with subsequent requests satisfied locally. To achieve this, use a local database for long-lived data (usually android.database.sqlite orSharedPreferences). This architecture also simplifies an app’s flow between offline and online states as one side fetches from the network to the cache, while the other retrieves data from the cache to present to the user.

The last method for optimization for low-speed connections and offline working is to Fine-tune data transfer. I wish i could continue, however i will discuss that in the next article.

Beware of bugs from Planet X….lol!!!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store