1
  1. Will using deprecated classes cause severe problems to the program?

  2. What is the meaning of deprecated?

  3. Can I still work with deprecated classes?

An example for it is the ProgressDialog view in Android. It deprecated from API 26 and the replacement is the ProgressBar view. What happens if I will still use the ProgressDialog? It is extremely comfortable and exactly what I was aiming for.

Daniel Reyhanian
  • 579
  • 4
  • 26
  • 1
    In theory, the deprecated libraries you are using should be supported indefinitely. However, the Google Play Store may at some point not support your API level, which means you might not be able to keep updating your app. – Tim Biegeleisen Feb 02 '19 at 15:38
  • Deprecation means it's no longer supported. If it stops working at some point, it won't be fixed. It might even be removed altogether eventually. – TheWanderer Feb 02 '19 at 15:39
  • for android you must use deprecated classes if you are targeting lower API's and newer alternatives are just for newer API's...but if newer alternatives also works for lower API's then don't use deprecated classes. – M.kazem Akhgary Feb 02 '19 at 15:42
  • @TimBiegeleisen What do you mean won't be able to update my app? A piece of code is a piece of code, no matter what. Please explain.. – Daniel Reyhanian Feb 02 '19 at 15:42
  • @M.kazemAkhgary That's what I dont get. My API level is 26. Which means that ProgressDialog is deprecated. Will it be deprecated for lower API's? And if I actually do switch it with the ProgressBar, will the lower API's be able to run the program? – Daniel Reyhanian Feb 02 '19 at 15:44
  • A piece of code is in the user's phone, not your app. so a user with newer API may have another piece of code, but your app is still referring to old deprecated code that may be removed and your app wont work – M.kazem Akhgary Feb 02 '19 at 15:44
  • "A piece of code is a piece of code". That's true... until that piece of code is removed. – devNull Feb 02 '19 at 15:45
  • So basically, it's super recommended to use the newest classes? – Daniel Reyhanian Feb 02 '19 at 15:45
  • This link is targeting Java, but the concepts still apply to your questions: https://stackoverflow.com/a/2941912/5803406 – devNull Feb 02 '19 at 15:47
  • Thanks a lot everyone. By the way, can a moderator lock a post? – Daniel Reyhanian Feb 02 '19 at 15:52
  • Its fine to use deprecated classes if you want to still target lower API's. it becomes a problem when you decide to go for newer API's. you should also test your app on new phone or emulators with latest API to see if it still works or not. if you test your app for API 26 and it works fine, then it always works fine on API 26. but a phone with API 28 may have troubles running your app. just test and you should be fine :) – M.kazem Akhgary Feb 02 '19 at 15:58
  • @M.kazemAkhgary So if it works fine on API 26, it will also work for the lower ones, but not necessarily for the higher ones? – Daniel Reyhanian Feb 02 '19 at 16:06
  • You should see when that method is deprecated. If its deprecated on API 15 then it may work on API 26 but have different behavior on API 19. So you should test all the API from 15 to 26. But android tries to keep it self as backwards compatible as possible. Most of the deprecations are just for giving a better method name or better overloads and alternatives. – M.kazem Akhgary Feb 02 '19 at 16:14
  • Thanks a lot again. How can I upvote comments and lock questions? – Daniel Reyhanian Feb 02 '19 at 16:23
  • Im afraid you can't. Why do you want to lock this post? If you can flag your own question then choose "in need of moderator intervention". – M.kazem Akhgary Feb 02 '19 at 16:29
  • Because I've already received my answers.. – Daniel Reyhanian Feb 02 '19 at 16:44

3 Answers3

3

From the documentation:

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.

So you can use some deprecated methods but it won't be the best practice because there are better alternative exists(but in some cases this can even be dangerous)

devNull
  • 3,849
  • 1
  • 16
  • 16
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
3

Yes and no. You can use them for maintaining old API levels, tacking into account that in newer android versions these classes may be removed. So usually you would wrap its usage in a if/else condition to use them only to maintain such functionality in old Android versions, only when there is no compatible replacement in newer versions.

API_1024
  • 479
  • 2
  • 13
  • Good note on using if/else condition for checking API level but backward compatible solutions already do this check so using newest methods and classes garauntees correct behavior on older devices as well. If the class is only for newer API then using if/else condition for checking API level may help. – M.kazem Akhgary Feb 02 '19 at 16:20
  • Absolutely right, I agree with you. Just to clarify that If/else in such scenarios should be used only when there are no backward compatible solutions. – API_1024 Feb 02 '19 at 17:15
1

Google has a bad habit of not maintaining back-compatibility which is an essential best practice in computer science and technology. I appreciate that deprecated means there are better alternatives and the comment "In theory, the deprecated libraries you are using should be supported indefinitely. However, the Google Play Store may at some point not support your API level, which means you might not be able to keep updating your app." is very pertinent. API level should be able to continue supporting those "deprecated" classes. I am very sure many of us can find several examples where so called "deprecated" are much better than their "updated" alternatives.