Android/Kotlin

다른 엑티비티에 데이터가 넘어갈때 알아야하는 사항들

컴공 윤서혜 학습일기 2021. 7. 11. 23:20

https://developer.android.com/guide/components/intents-filters?hl=ko 

 

인텐트 및 인텐트 필터  |  Android 개발자  |  Android Developers

An Intent is a messaging object you can use to request an action from another app component . Although intents facilitate communication between components in several ways, there are three fundamental use cases: An Activity represents a single screen in…

developer.android.com

새로운 엑티비티에 값을 전달하려면 다음과 같은 원리를 아는것이 좋습니다.

 

 

 

 

MainActivity에서 intent를 이용하여, height와 weight값을 받습니다.

 

자바와 달리 getIntent라고 선언하지 않아도, intent로 값을 받아 올 수 있습니다.

그리고 그 값의 이름도 선언해주고, 기본값을 0으로 설정해주었습니다.

 

또한 pow라는 함수로 이용하여 좀더 코틀린 답게 선언을 하였고, when을 이용하여 출력값을 깔끔하게 정의해 보았습니다.