Designers and developers have been afraid of the variety of Android flavors for way too long. Android borrows a lot of concept from the web, and we can use the same techniques to cater to the different OS versions and form factors.
Be responsive. Forget about absolute coordinates. Embrace the relative, use resource folders to differentiate among screen sizes, much like CSS media queries.
Be progressive. Take advantage of the latest Android functionalities, but gracefully fall back to the basics when you are on older OS versions. Remember the days when not all browsers have javascript?
67. Progressive
// Default value
int heapSize = 16;
// Detect OS version
int sdk = Integer.parseInt(Build.VERSION.SDK);
// Progressive enhancement for newer devices
if (sdk >= Build.VERSION_CODES_ECLAIR) {
// Static helper for API level 4 and below
heapSize = HeapSizeGetter.getHeapSize(this);
}
@chiuki
68. Static helper
public abstract class HeapSizeGetter {
public static int getHeapSize(Context context) {
ActivityManager activityManager = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
return activityManager.getMemoryClass();
}
}
@chiuki
69. Progressive
// Default value
int heapSize = 16;
// Detect OS version
int sdk = Integer.parseInt(Build.VERSION.SDK);
// Progressive enhancement for newer devices
if (sdk >= Build.VERSION_CODES_ECLAIR) {
// Static helper for API level 4 and below
heapSize = HeapSizeGetter.getHeapSize(this);
}
@chiuki