Android Kotlin - Recyclerview 中的 registerForActivityResult
Android Kotlin - registerForActivityResult inside Recyclerview
我试过了:
val getUpdates = (context as Activity).registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
}
}
在 RecyclerView 中得到:Unresolved reference: registerForActivityResult
在RecyclerView里面不可以吗?
您尝试执行的操作将导致崩溃。结果回调必须在 Activity 创建时注册(即作为 Activity 的 field/variable)
the callback must be unconditionally registered every time your activity is created, even if the logic of launching the other activity only happens based on user input or other business logic.
有关详细信息,请参阅 docs
我试过了:
val getUpdates = (context as Activity).registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
}
}
在 RecyclerView 中得到:Unresolved reference: registerForActivityResult
在RecyclerView里面不可以吗?
您尝试执行的操作将导致崩溃。结果回调必须在 Activity 创建时注册(即作为 Activity 的 field/variable)
the callback must be unconditionally registered every time your activity is created, even if the logic of launching the other activity only happens based on user input or other business logic.
有关详细信息,请参阅 docs