Reputation: 5717
I'm quite confused how application behaves when launched on different Android versions.
Let's say I'm compiling it using SDK level 4. Is it compiled in the code and when running it on phone with SDK 10 will still use the old SDK 4, or it will use SDK 10?
A simple example is Service's setForeground()
-method, which was deprecated. If I run such code on phone with SDK 10, will the function have no effect or it will use the version from SDK 4?
The same goes for onStart()
being deprecated. Is it going to be ignored on SDK 10 and it will try to call onStartCommand()
?
I'd be thankful if somebody could explain me what's gonna happen here and why.
Upvotes: 2
Views: 2307
Reputation: 10343
Most deprecated api calls on most phones will work... However, some, like your given example of setForeground() have been removed due to the fact that developers have misused it (setting a service into the foreground without notifying users). So they WILL NOT work. Unfortunately, there is no documentation to which ones are supported and which ones aren't so it's a trial and error thing...
Also, there are differences between different implementations (phone manufacturers / models) for some reason. A good example is the old Contacts APi (pre V2.0) which works on some newer phones with Android 2.2/2.3 and doesn't work on others with the same OS versions... The best bet would be NOT to use deprecated methods, and to adjust according to the current popularity of the Android OS version (currently 2.1, 2.2, 2.3.2, 2.3.3 are the popular versions: http://developer.android.com/resources/dashboard/platform-versions.html).
Upvotes: 2
Reputation: 12367
Your service is just compiled bytecode - with own classes and references to other classes and methods. When it is deployed on newer android version, it (android, OS) will do whatever it sees fit - you have no influence there. As other java based systems, it will rely on proper class names / packages / interfaces, and try to resolve methods with certain signatures ( parameters and return values). If it behaves socially, it would first check if there is method from newer interface ( i.e. onStartCommand() ), and if it is available it will be called. Then it may (or not) fallback to older method. But usually you can rely that reverse compatibility is maintained pretty long time.
Upvotes: 2
Reputation: 200080
Is it compiled in the code and when running it on phone with SDK 10 will still use the old SDK 4, or it will use SDK 10?
SDK means Software Development Kit, thus devices do not run anything using the SDK. On the other hand, devices have different kind of OS which belongs to a specific API.
If you run a build compiled using SDK 4, and run it in a device which runs API 10, it will run it using the new API (that's called, backwards compatibility).
Usually, deprecated functions are supported on newer versions of the SDK. Most of them will work, but you must try to not use them. Of course, there are cases where you have no choice, for instance, when the method you are using is deprecated but there is no replacement in the old SDK that you are using.
Upvotes: 4