액티비티 콜백 등록을 click listener에 넣으면 안되는 이유 #34
Unanswered
KimGyeongyeon
asked this question in
프로젝트 회고
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
registerForActivityResult(ActivityResultContracts.StartActivityForResult())
이 코드는 Activity result API를 사용해서 다른 액티비티의 결과값을 반환받는 콜백이다.
콜백 선언부가 onCreate에 너무 길게 있어서, 아예 인텐트 이동 작업 직전에 선언해주면 되겠다 하고 click listner에 선언했더니 registerForActivityResult를 호출하자마자 앱이 터졌다.
공식문서를 읽어보니 아래와 같은 설명이 있었다.
생성과 관련된 위치가 아닌 곳에서 등록을 시도하면 막아버리는 코드가 내부에 있지 않았나 싶다.
따라서 등록을 함수로 빼고싶다면 람다함수 넘기는 부분만 함수로 빼던가 해야할 것같다.
Beta Was this translation helpful? Give feedback.
All reactions