Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated Classess on Android

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.

like image 466
Emrullah Kızıltepe Avatar asked Mar 01 '12 12:03

Emrullah Kızıltepe


People also ask

Can I still use deprecated methods in Android?

What happens if i continue using Deprecated methods? Code would continue running as it is until method is removed from SDK. If you are using deprecated method then you must keep track of removed apis whenever you upgrade to newest SDK.

What are deprecated classes?

Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future. The need for deprecation comes about because as a class evolves, its API changes.

What does deprecated mean in Android?

Deprecation means that we've ended official support for the APIs, but they will continue to remain available to developers. This page highlights some of the deprecations in this release of Android. To see other deprecations, refer to the API diff report.


2 Answers

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

like image 86
Nick Avatar answered Sep 19 '22 06:09

Nick


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 :)

like image 31
N3WB13 Avatar answered Sep 18 '22 06:09

N3WB13