gpt4 book ai didi

android - 检查 SDK_INT 是否足够或是否需要使用更新的 android API 进行延迟加载?为什么?

转载 作者:搜寻专家 更新时间:2023-11-01 08:01:49 26 4
gpt4 key购买 nike

代码如:

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
ed.apply();
else ed.commit();

在 Froyo 中产生警告:

04-27 03:40:35.025: W/dalvikvm(3138): VFY: unable to resolve interface method 219: Landroid/content/SharedPreferences$Editor;.apply ()V

但我知道,在旧设备中,这将是一个 RuntimeError,它会中止应用程序(请参阅 herehere)。

那么这种有条件地调用新 API(方法)的方式在 API 8 (Froyo) 及更高版本中是否安全,或者在某些情况下仍然需要延迟加载?

Dalvik 的哪些变化使这成为可能?

相关

最佳答案

produces a warning in Froyo

这是完全正常的。

But I understand that in older devices this would be a RuntimeError which would abort the application

对于 Android 1.x,是的。

So is this way of conditionally calling new API (methods) safe in API 8 (Froyo) and above

是的。

What changes on Dalvik made this possible ?

它不再遇到未识别的符号时“快速失败”,而是等待语句执行时再次尝试解析它。通过检查 SDK_INT 并确保语句未执行,您不会崩溃。

关于android - 检查 SDK_INT 是否足够或是否需要使用更新的 android API 进行延迟加载?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20271593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com