不推荐使用的代码可以在所有Android版本和设备上安全地运行?

时间:2021-03-30 18:23:52

I am working on a huge android project with tons of classes. Until now we are compiling with Android 3.2 and giving support to android 2.3.

我正在开发一个庞大的Android项目,有很多课程。到目前为止,我们正在使用Android 3.2编译并支持android 2.3。

Now i am testing to compile with Android 5.1.1, but still giving support to android 2.3. My surprise was that a lot of code is deprecated now... (getWith, getDrawable, setBackgroundDrawable, httprequest, activitygroup, etc...). Those deprecated functions does not give compile error, but it gives deprecated warning.

现在我正在测试用Android 5.1.1编译,但仍然支持android 2.3。令我惊讶的是,现在很多代码都被弃用了...(getWith,getDrawable,setBackgroundDrawable,httprequest,activitygroup等...)。这些已弃用的函数不会产生编译错误,但它会提供已弃用的警告。

I know that i can duplicate code and make special calls to deprecated methods if SDK_INT is lower than XX and calls to new methods if SDK_INT is newer than XX, but this is a huge patch, that will need a lot of duplicate code in a lot of functions in a ton of classes and packages, so, if it is possible, we prefeer to wait until we don't need to give support to oldest versions of android. It means to continue using deprecated methods until for example we only need to give support from 4.4, that will means munch less duplicated code and functions will be needed.

我知道如果SDK_INT低于XX,我可以复制代码并对已弃用的方法进行特殊调用,如果SDK_INT比XX更新,则调用新方法,但这是一个巨大的补丁,需要大量的重复代码大量的类和包中的函数,所以,如果可能的话,我们会先等待,直到我们不需要支持最老的android版本。这意味着继续使用已弃用的方法,例如我们只需要提供4.4的支持,这意味着需要更少的重复代码和功能。

The question is: If i compile with Android 5.1.1 but still use those deprecated functions, this huge project will continue to work on all devices (from 2.3 to 5.1.1)? Now it's working compiling with Android 3.2.

问题是:如果我使用Android 5.1.1进行编译但仍然使用这些已弃用的函数,这个庞大的项目将继续适用于所有设备(从2.3到5.1.1)?现在它正在使用Android 3.2进行编译。

I understand that 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, but if it is still supported and does not give a compile error, it will work well as until now. It is what i understand of deprecation. It is right?

我知道Deprecated意味着它们可能会在未来版本的平台中删除,因此您应该开始考虑替换它们在代码中的使用,但是如果它仍然受支持并且不会产生编译错误,那么它将起作用直到现在。这是我对弃用的理解。这是正确的?

Thanks

2 个解决方案

#1


0  

Deprecated means two things:

弃用意味着两件事:

  1. There is another (maybe better) solution
  2. 还有另一种(可能更好的)解决方案

  3. It isn't fully support anymore
  4. 它不再完全支持

That means that your code could be run fine. But Google/Android don't guarantee that.

这意味着您的代码可以正常运行。但Google / Android不保证这一点。

According to Java documentation the @Deprecated annotation says:

根据Java文档,@ Deprecated注释说:

@Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation. [...]

@Deprecated注释表示已弃用标记的元素,不应再使用。只要程序使用带有@Deprecated注释的方法,类或字段,编译器就会生成警告。 [...]

So please stop using deprecated methods. :)

所以请停止使用弃用的方法。 :)

Have you looked or do you know that there are support-librarys to help you with backward compatibility?

您是否看过或者您知道有支持 - 图书馆可以帮助您实现向后兼容吗?

#2


0  

Yes it should work fine. But you really should use the latest methods instead of deprecated ones and use support libraries to make it compatible to the previous versions. All the deprecated methods that I have used have worked fine, but Google does not guarantee that they will.

是的它应该工作正常。但是你真的应该使用最新的方法而不是弃用的方法,并使用支持库使它与以前的版本兼容。我使用过的所有已弃用的方法都运行良好,但Google不保证会这样做。

#1


0  

Deprecated means two things:

弃用意味着两件事:

  1. There is another (maybe better) solution
  2. 还有另一种(可能更好的)解决方案

  3. It isn't fully support anymore
  4. 它不再完全支持

That means that your code could be run fine. But Google/Android don't guarantee that.

这意味着您的代码可以正常运行。但Google / Android不保证这一点。

According to Java documentation the @Deprecated annotation says:

根据Java文档,@ Deprecated注释说:

@Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation. [...]

@Deprecated注释表示已弃用标记的元素,不应再使用。只要程序使用带有@Deprecated注释的方法,类或字段,编译器就会生成警告。 [...]

So please stop using deprecated methods. :)

所以请停止使用弃用的方法。 :)

Have you looked or do you know that there are support-librarys to help you with backward compatibility?

您是否看过或者您知道有支持 - 图书馆可以帮助您实现向后兼容吗?

#2


0  

Yes it should work fine. But you really should use the latest methods instead of deprecated ones and use support libraries to make it compatible to the previous versions. All the deprecated methods that I have used have worked fine, but Google does not guarantee that they will.

是的它应该工作正常。但是你真的应该使用最新的方法而不是弃用的方法,并使用支持库使它与以前的版本兼容。我使用过的所有已弃用的方法都运行良好,但Google不保证会这样做。