Tom*_*tel 6 android lint kotlin android-studio
fun newInstance(message: String?): DialogFragment {
return DialogFragment().apply {
arguments = Bundle().apply {
putString("arg", message)
}
}
}
Run Code Online (Sandbox Code Playgroud)
该消息指出函数this
内部的引用apply()
指向BaseBundle
自API 21以来可用的类,它将在较低的API上崩溃.Bundle #putString(key,value)绝对可用于较低版本,但Android Studio 3.0-alpha8中存在错误.
哪个参考Bundle
类型不是BaseBundle
.
为什么我们首先有Lint错误?
一种解决方法是使用let
代替apply
,例如:
fun newInstance(message: String?): DialogFragment {
return DialogFragment().apply {
arguments = Bundle().let {
it.putString("arg", message)
it
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
190 次 |
最近记录: |