Optimizing Your Apps For Emerging Markets
#DroidconMtl
+VinayGaba@vinaygaba
Emerging MarketsDrive Growth
Source: Mediacells via The Guardian
Source: Mediacells via The Guardian
44
36
21
5137
11
80
109
25
66
9
Smartphone Feature phone Multimedia phone
Brazil Russia
India China
1. Optimizing App Size
The smaller, the better
Color Filters
Use Color Filter
• Faster way to experiment with color schemes.• Reduce the number of assets, which in turn reduces
the apk size.• Less memory used as the number of assets are
reduced.
Code
ImageView redCircle = (ImageView) findViewById(R.id.circle_red_imageview); ImageView greenCircle = (ImageView) findViewById(R.id.circle_green_imageview); ImageView blueCircle = (ImageView) findViewById(R.id.circle_blue_imageview); // we can create the color values in different ways: redCircle.getDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY ); greenCircle.getDrawable().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY ); blueCircle.getDrawable().setColorFilter(getResources().getColor(R.color.blue),PorterDuff.Mode.MULTIPLY );
Image Optimizatio
nsColor Filters
JPEG WEBP PNG GIF
Lossy
Lossless
Transparency
Animation
WebP
No Noticeable Change
PNG24 kb
WebP10 kb
Compatibility
• You can use the native WebP decoder on 4.2 and later.• For lower versions, use libpng to convert to PNG
format and then use it in the app.
Other Libraries
• Use programs like OptiPNG, TruePNG and PNGCrushto significantly reduce the size of PNG images.• Use mozjpeg for jpeg images.• 5-10% size reduction
• Won’t cause any visible changes to the images.
Remove Unused Content
Image Optimizatio
nsColor Filters
Remove Unused Content
• Use Resource Shrinking.
Code
android { ... buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
Remove Unused Content
• Use Resource Shrinking.• Use tools like Lint and ProGuard.• Use Android-Unused-Resources jar file if you are
still using Eclipse.
https://code.google.com/p/android-unused-resources/
2. Optimizing NetworkCalls
Expensive Data
Flaky Networks
Challenges
Build for Failure
Most efficient way to transfer is to not transfer
Image Scaling
Appropriate Image Size
• Store multiple image sizes on the server• Low-res devices might never need a full resolution
image• Most times the smallest image size is sufficient.
ChecksumImage Scaling
Client A Client BServer
Checksum
ID
Send File ID
Transfer File
CS ID
Code
public static String getMD5EncryptedString(String encTarget){ MessageDigest mdEnc = null; mdEnc = MessageDigest.getInstance("MD5"); // Encryption algorithm mdEnc.update(encTarget.getBytes(), 0, encTarget.length()); String md5 = new BigInteger(1, mdEnc.digest()).toString(16); while ( md5.length() < 32 ) { md5 = "0"+md5; } return md5; }
Checksum
• Avoid transfers as much as possible.• For file transfers, first compute the md5 checksum
and send it to the server to check if it already existson the server. • The cost to upload the entire file again can be
avoided.
Image Scaling Checksum Transfer in
Blocks
Transfer in blocks
• Do data transfers in blocks.• Keep track of the blocks that have been transferred
and yet to be transferred.• The block size can vary based on the type of
connection.
Testing for different networks is a pain
Testing for different networks
• Facebook recently open-sourced Augmented Traffic Control (ATC).• It is a tool to simulate network conditions.• It can simulate 2G, Edge, 3G, and LTE networks.• Has multiple profiles for a lot of different countries.
http://facebook.github.io/augmented-traffic-control/
3. Optimizing for DifferentPhones
Small Screens
Slow Processing
Challenges
Developing for flagshipdevices is easy
Year Class
Code
int year = YearClass.get(getApplicationContext()); if (year >= 2013) { // Do advanced animation} else if (year > 2010) { // Do simple animation } else { // Phone too slow, don't do any animations}
https://github.com/facebook/device-year-class
RedesignYear Class
Redesign
• Remove features from low-end devices if they won’thave the best user experience.• This could be animations, videos or even
functionalities.• No feature >>> Bad feature
@vinaygaba
Questions?
Top Related