Is it possible to use so many obsolete methods in reverse code?

I am writing an Android application that is designed for API level 15, but I also want to keep compatibility with old API levels (min-sdk 7).

I am going to achieve this by setting conditions that determine which code to use according to the current API level (as shown below). I believe this is a good approach, I just want to ask if it has so many deprecated methods (e.g. display.getWidth() ) because there are quite a lot of changes between API levels 8 and 15. And if so, if it is useful to use @SuppressWarning("deprecation") in this case?

Wouldn't it be better to use multiple APKs, for example, for API levels <= 8 and> = 9? (Even if this is not recommended by developer.android.com .

  Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point screenSize = new Point(); // calculate the width float width; if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(screenSize); width = screenSize.x; } else { width = display.getWidth(); } 

Thanks!

+7
source share
1 answer

You should ask yourself a few questions:

  • Was it deprecated for the API levels that would execute this code?
  • If so, is an alternative proposed or available?

In your case, getWidth() deprecated in favor of using getSize(Point) , which requires API level 13. Thus, up to API level 13, all you have is getWidth() , which at that time was not deprecated. The reason these legacy methods are supported is mainly due to backward compatibility (along with not breaking all applications that depend on it).

So, to answer your questions, yes, in this case it’s good, and yes, it is a good use of @SuppressWarning("deprecation") .

+9
source

All Articles