Even though I have done some app on android, I am still confused. Is it possible to use functions in SDK 4.0, and run the app on android 2.1 or lower?
I tried methods you guys mentioned but got an error –
Field requires API level 11 (current min is 7): android.os.AsyncTask#THREAD_POOL_EXECUTOR, if I change min to 11, the app can’t install on android 2.1, so even I can use higher API, but it still can’t run on android lower version…how to fix that?
From Kzinch’s advice, set TargetApi to 11, then it’s working!
Yes, you can use functions from the higher API in your code, but you must make sure they are never called on the lower API in runtime.
You should make checks for API level in runtime and provide alternative implementation that exists for that API level.
Let me provide some simple example:
apply()method is a faster (asynchronous) implementation ofcommit()method, but it not supported on the API level less than 9. With the help of API version check it all works perfect for all devices.Update @TargetApi annotaion may be used to suppress Lint warnings/errors for API checks.