Similar questions have been asked, but the provided answers did not really help me.
Say I'm using a deprecated method and my minApiLevel is X. The suggested replacement of the deprecated method has api level Y.
What should I do when Y > X (and I can't or don't want to increase X)? As a rule of thumb (if there's one), can I safely ignore this (meaning it will never work unexpectedly on Android versions where the method's deprecated), or should I rather implement both variants and put them in an if-else depending on the SDK version? (Assuming I'm satisfied with the functionality of the old deprecated method.)
When an element is marked as deprecated, an alternative will generally be offered, and therefore both variants must be implemented, using if/else branching for the newer and older API levels.
It is bad practice and discouraged to keep using deprecated elements. In addition consider that it may eventually no longer work and be removed in future API levels, forcing to revisit and rewrite your implementation.
A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code.
https://developer.android.com/reference/java/lang/Deprecated#:~:text=A%20program%20element%20annotated%20%40Deprecated,overridden%20in%20non%2Ddeprecated%20code.
What happens if continuing to use Deprecated elements:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With