2023 Feb. 25.
出典ページ
registerForActivityResultで「attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.」 - Qiita
メソッド定義の中で記述すると「attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED」エラーとなる。
class MainActivity : AppCompatActivity() { private val startAnotherAppForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult? -> if (result?.resultCode == Activity.RESULT_OK) { result.data?.let { data: Intent -> // Do your work } } } private fun myMethod() { val intent = Intent( 適当なIntentをセット ) startAnotherAppForResult.launch(intent) } }