RockandRoll
RockandRoll

Reputation: 411

Why to specify targetsdkversion and why it has to be always have latestsdk value?

I have seen lots and lots of question on targetsdk version in android. but not pretty clear about the explanation. i think its bit tricky compared to minsdk and maxsdk version. i had gone through developer.android.com and read about uses sdk tag, and few video explaining this concept. but dint get clear picture of targetsdk version. as i said before there are already thousands of question and answers on stack overflow, i am posting this again to get simple and clear solution for this problem. so please guys kindly bear with this question and help me out.

This is statement in developer.android.com.

However, if the API level of the platform is higher than the version declared by your app's targetSdkVersion, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect. You can disable such compatibility behaviors by specifying targetSdkVersion to match the API level of the platform on which it's running.

I did small sample where i specified targetsdkversion to 14 and i tried to run on android api level 19 (android 4.4), my app was installed without any problem and is working fine.

if i remove targetsdkverion then by default it will be set to minsdkversion value , and again my app got installed and is working fine.

My sample and the above statement both are contradicting, so i am getting confused about the concept. kindly explain me in details with a simple explanation to with video tutorial.

Q1) now if i specify targetsdkversion will there be forward compatibility? ( i hope that backward compatibility will be there rite.

Q2) why everyone say that we should always set targetsdk version to latest version release?

Q3) In what scenarios do we have to specify targetsdkversion lower than latest version release number. and what are the effects of this? (i.e targetsdkversion = 14 and maxsdkverion= 19).

Please guys need your help on this. Thanks..

Upvotes: 0

Views: 773

Answers (1)

Leo
Leo

Reputation: 14860

I did small sample where i specified targetsdkversion to 14 and i tried to run on android api level 19 (android 4.4), my app was installed without any problem and is working fine.

This doesn't mean anything. I believe that in most case it will behave just fine, however, there might be some features that could behave or look a bit different...I don't know, themes, UI, etc. All it tells is that SDK versions are forward-compatible, once you have done that same test for every single SDK version, every single Android feature, on every single Android device then you might bump into the facts that you should follow the guidelines and set the TargetSDK to the latest version

now if i specify targetsdkversion will there be forward compatibility? ( i hope that backward compatibility will be there rite

This is a hard question to answer since we never know what will happen to Android in the future, but as it stands now the Android Team is striving to keep API Level "forward-compatible" even if it requires the system to enable compatibility behaviors

why everyone say that we should always set targetsdk version to latest version release?

This is a best practice guideline that evolves around not making the system to enable compatibility behaviors since this "might" make your app behave a bit different is the targetsdk of your app is lower than the current system it's running on

In what scenarios do we have to specify targetsdkversion lower than latest version release number. and what are the effects of this? (i.e targetsdkversion = 14 and maxsdkverion= 19)

As stated above you should always target the latest sdk version. maxSdkVersion has been discouraged by the Android and you should NOT use this setting in order to avoid certain issues related to system updates. To be more specific here's an extract from the documentation...

In Android 1.5, 1.6, 2.0, and 2.0.1, the system checks the value of this attribute when installing an application and when re-validating the application after a system update. In either case, if the application's maxSdkVersion attribute is lower than the API Level used by the system itself, then the system will not allow the application to be installed

So, the effect is pretty clear users might not be able to install your application.

So, to wrap it up, if you still don't get it, my advice is that you should follow what the Android Documentation considers as best practice, at least you'll have the piece of mind that some smarter people are taking care of something you can't understand :P

Edit based on comment

Compatibility behaviour is just a very general term used by Android to describe when how it evaluates to perform different routines or features for apps built for a lower SDK version. One example is how Android treats obsolete permissions. For example, imagine you have an API Level 8 device running an app that targets the same API Level and this app requests PERSISTENT_ACTIVITY Permission which has been deprecated in API Level 8. What'd happen is that android will evaluate this permission effectively?

Now, consider the same app targeting the same API Level but this time running on KitKat. What'd happen? I don't exactly know, but an educated guess is that Android will enable compatibility behaviour to ignore this permission. Got it now?

Upvotes: 1

Related Questions