0

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..

pavel
  • 26,538
  • 10
  • 45
  • 61
RockandRoll
  • 409
  • 5
  • 23

1 Answers1

1

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?

Community
  • 1
  • 1
Leo
  • 14,625
  • 2
  • 37
  • 55
  • Leo, what do u mean by compatibility behaviors? can u explain in more detail please? – RockandRoll Oct 14 '14 at 07:10
  • @RockandRoll No, I can't go into details because it'd be too extensive and there are lots of resources out there already. I'll add an edit in my answer but only to highlight a case on android enabling compatibility behaviors which is by fa a very general term – Leo Oct 14 '14 at 07:17
  • @RockandRoll I just added an edit to give you a better illustration of how compatibility behaviour works – Leo Oct 14 '14 at 07:29
  • Ok.. Thanks Leo.. Got it. Appreciate your help. The final conclusion of this question would be. Specifying TargetSDkversion does not restrict our app to be forward and backward compatible. but it will not allow app to adapt compatible behaviors. i.e it will tell android system to use only those API that are present in that Perticular API Level.. rite? – RockandRoll Oct 14 '14 at 07:44
  • @RockandRoll sort of...put it this way, it tells android to run the app in a "sandbox" for that API Level which means your app might not look like the rest of the system, simple. – Leo Oct 14 '14 at 08:14