5

I have been making a project on Android 4.0 and I have faced some deprecated types for the newer versions of Android. A black line has occured on the name of the deprecated things. However, in spite of the black line and the deprecation warnings, I can still use those deprecated classes and project is running successfully. I got confused about the deprecation. If they are deprecated how can I still use them and what does deprecation mean exactly? If I use the deprecated classes in my project, what can be the possible disadvantages that the project users can encounter?

Thanks for reading.

4 Answers4

6

Deprecated means that they are likely to be removed in a future version of the platform and so you should begin looking at replacing their use in your code.

If they just removed the types then builds would break and people wouldn't be happy!

In terms of the effect they will have on your application's users, there shouldn't be any effects at all. However, when you come to update your software to the next version of Android you may find that the deprecated types are no longer there and your build will break.

Wikipedia has a good article on it here: http://en.wikipedia.org/wiki/Deprecation

Nick
  • 25,026
  • 7
  • 51
  • 83
3

Long story short only use the deprecated method on systems running too low of an API to support the updated method. This way you can support a wider range of devices while only using the deprecated methods when you have to to support the older devices. Code example below.

    int sdk = android.os.Build.VERSION.SDK_INT;
    if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        setBackgroundDrawable(); // deprecated method for older devices
    } else {
        setBackground();  // updated method for newer devices
    }

CHEERS :)

N3WB13
  • 31
  • 1
1

Don't forget that there is probably a reason for these classes to be deprecated. It might affect the security or stability of your app. If you find out there is a bug or a flaw it will probably never be corrected.

Also checkout what classes they advise to use instead, if any.

Concerning your worries about newer Android versions:

Android versions are backward compatible

Confirmed here by an Android engineer in a topic about an other deprecated class. Therefore you should be able to use your app on newer versions.

If you want your application to be compatible with older versions of android while using a "new" class in your code, check this related topic.

Community
  • 1
  • 1
Jla
  • 11,304
  • 14
  • 61
  • 84
0

often some types of classes are deprecated but you can still continue using them because to update applications and implement those classes you would have to modify the source code.

But if you find that there are unused classes is better than in coming soon applications no longer use them, personally I spend it with ClipboardManager and use applications where previously it still works.