Is it possible to "graceful degrade" an android application?
Asked Answered
A

3

7

I am wondering if it is possible to use graceful degradation approach in an Android application. I.e, use some functions of, say, API 15 but if it is not supported, use API 10 instead.

Specifically, I have "swiping tabs" in Android 4 vs. missing support of this feature in Android 2.x (and thus using normal tabs) in mind but the question is rather general.

I would like to use an advanced functionality on devices that support it but when it is not supported, I would like to use an alternative. I don't seem to be able to use Android 4 libraries in an Android 2 project while an Android 4 project will not, understandably, be launchable on an Android 2 device.

Any solution? Or, at least and for this moment, any solution for "swiping tabs" on Android 2?

Algernon answered 25/10, 2012 at 16:34 Comment(0)
E
5

Part 1: To be able to use functionality for newer APIs, make sure your manifest declares your android:minSdkVersion to the lowest version (10, in your case), but set the android:targetSdkVersion to the newer version with APIs you want to use (15). In your code, you can do something like

if ( Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH ) {
    // Use the new APIs
} else {
    // Use the old APIs
}

You'll have to add an Annotation to indicate the new API usage.

Part 2: Swiping Tabs - I've used Jake Wharton's ViewPagerIndicator and the ViewPager functionality in the Android Support Library to achieve swiping tabs. It's pretty simple. There is more information at the ViewPagerIndicator page

Hope this helps.

Exempt answered 25/10, 2012 at 16:44 Comment(1)
Thanks. Will check it out. I know applications are capable of the effect in Android 2 but I didn't have any idea how they did that...Algernon
F
1

Make sure to use the @TargetApi directive above the class or function that only works with the newer version of the API. For example

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void foo() {

  /* function called only on ice cream sandwich (API level 14) and greater */

}
Feleciafeledy answered 29/4, 2013 at 12:7 Comment(0)
A
1

I know you already marked your answer, but maby this could help you, its an android library called actionbar sherlock that has backported 4.x functanlities to 2.x. including fragments, pagers, tabs and the Actionbar introduced in 3.0

Alburga answered 29/4, 2013 at 12:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.