Yea! Yea! Yea! I am right back to wrap up android connectivity. In the last article i expounded on a couple of best practice methods you can consider while building your app for the billions.This is to ensure that your app users have an amazing experience. If you didn’t follow my part 1, don’t worry i have got you covered.
Please go to https://medium.com/@temidjoy/best-practice-android-connectivity-for-billions-part-1-995c3513c80c for my part 1. This will give you an overview of the whole concept of Android Connectivity.
Okay lets get started. In the previous article i shared two tips on how to optimize for low-speed connections and offline working by storing data, queuing requests, and handling images for optimal performance. Today i am dropping the last one.
3. Fine-tune data transfer
In android, there are diverse ways in which your app can adapt to network conditions to provide more excellent user experience. For instance, it can prioritize network requests to minimize the user’s waiting period for information. It can as well easily detect and adapt to sluggish network speeds and changes that may take place in the network connection.
Prioritize bandwidth
- Most of the time Android developers assume that any network that the device is connected to is long-lasting or reliable,DON’T DO THIS!!!. It’s important to note that not every device will have a super fast internet to use your app. For this reason, apps should prioritize network requests to display the most useful information to the user as soon as possible.
- Users don’t want to wait for your app to load forever.However, presenting users with visible and relevant information immediately is a better user experience than making them wait for information that might not be relevant. This reduces the time that the user has to wait and increases the usefulness of the app on slow networks.
- To achieve this, sequence your network requests such that text is fetched before rich media. Text requests tend to be smaller, compress better, and hence transfer faster, meaning that your app can display relevant content as fast as possible.
https://gist.github.com/Temidtech/56a5c152aef456b201ca3c53526793b7
Use less bandwidth on slower connections
- The ability for your app to transfer data in a timely fashion is dependent on the network connection. Detecting the quality of the network and adjusting the way your app uses it can help provide an excellent user experience.
- You can use the following methods to detect the underlying network quality. Using the data from these methods, your app should tailor its use of the network to continue to provide a timely response to user actions:
ConnectivityManager
> isActiveNetworkMetered()
ConnectivityManager
> getActiveNetworkInfo()
ConnectivityManager
> getNetworkCapabilities(Network)
TelephonyManager
> getNetworkType()
- On slower connections, you can consider downloading only lower-resolution media or perhaps none at all. This ensures that your users can use the app on slow connections. Where you don’t have an image or the image is still loading, you should always show a placeholder. You can create a dynamic placeholder by using the Palette library to generate placeholder colors that match the target image.
https://gist.github.com/Temidtech/5563e58311c3f8e9909c036517693c8e
- On devices powered by Android 7.0 (API level 24) and higher, users can turn on the Data Saver setting, which helps minimize data use. Android 7.0 extends
ConnectivityManager
to detect Data Saver settings. For more information about this feature, see Data Saver.
Before i dive into the last part of this article, quickly grab a cup of coffee!!
Welcome back from the short break!!!
Detect network changes, then change app behavior
- Network quality is not static; it changes based on location, network traffic, and local population density. Apps should detect changes in network and adjust bandwidth accordingly. By doing so, your app can tailor the user experience to the network quality. Detect network state using these methods:
ConnectivityManager
> getActiveNetworkInfo()
ConnectivityManager
> getNetworkCapabilities(Network)
TelephonyManager
> getDataState()
- On higher quality, unmetered networks, consider prefetching data to make it available ahead of time. From a user experience standpoint, this might mean that news reader apps fetch three articles at a time on 2G but fetch twenty articles at a time on Wi-Fi. For more information on adjusting app behavior based on network changes, visit the Android training on Monitoring the Connectivity Status.
Congratulations!!You just leant how to optimize apps for low-speed connections and offline working by storing data, queuing requests, and handling images for optimal.
I have shared tips on android connectivity best practice. In my next article i will be discussing another amazing stuff “Device capability for billions”. Feel free to follow me on this platform and also contribute in the comment section of this article.
Thanks for reading!
No Comment! Be the first one.