Intent(Explict Intent)

Posted by Eun JongHyeok on December 30, 2020
  1. Intent
  2. Intent types
  3. Intent Information
  4. Reference

먼저 Explict Intent 위주로 정리합니다.

Intent

App Component 사이에서 통신하는데 사용되는 메시지 객체입니다. ART에 요청하여 액티비티를 시작하거나 다른 app component(서비스, 브로드캐스트)등을 자기 앱에서 또는 다른 앱에서 실행 시킬 수 있습니다.

앱을 처음 실행시킬때 ART에서 앱으로 Intent를 보내 메인 액티비티를 실행시킵니다. 다른 액티비티를 실행시킬때는 startActivity() 또는 startActivityResult()를 호출합니다. 실행 뿐만 아니라 액티비티간 데이터를 전송하는데 사용할 수도 있습니다.

Intent types

  • Explict Intent

주로 자신의 앱에서는 패키지 이름과 클래스 이름을 알고 있으므로 자격을 갖춘 액티비티 클래스 이름을 사용하여 명시적으로 인텐트를 호출 할 수 있습니다.

  • Implict Intent

명시적으로 지정하지 않고 수행할 액션을 통해 시스템이 부합하는 액티비티 또는 컴포넌트를 실행시킬 수 있습니다. Implict Intent에 따로 정리합니다.

Intent Filter

AndroidMainfest.xml 에서 인텐트 필터를 확인한 적이 있습니다. 해당 구성 요소가 수신하고자 하는 인텐트 유형을 작성하면 됩니다.

보안상 Service를 시작할 때는 명시적 인텐트를 사용하고 서비스에 대한 인텐트 필터는 선언하지 말라고 합니다.

Caution: To ensure that your app is secure, always use an explicit intent when starting a Service and do not declare intent filters for your services. Using an implicit intent to start a service is a security hazard because you can’t be certain what service will respond to the intent, and the user can’t see which service starts. Beginning with Android 5.0 (API level 21), the system throws an exception if you call bindService() with an implicit intent.

Intent Information

Intent 내부에는 어떤 컴포넌트를 실행할지 등 정보들이 담겨있습니다.

  • Component name

Explict Intent에서는 필수로 작성해야합니다. 컴포넌트 이름이 없으면 시스템은 Implict Intent로 판단하고 다른 정보들을 통해 매칭해줍니다.

  • Data

작업을 수행할 데이터의 URI와 MIME 유형을 전달할 수 있습니다. URI를 설정하기 위해서는 setData()를 MIME 유형을 설정하기 위해서는 setType()을 호출하면 됩니다.

단, 주의 사항으로 URI와 MIME 유형을 둘다 설정할 경우 setData()와 setType()를 호출하는게 아니라 setDataAndType()을 호출합니다. 그렇지 않을 경우 서로 무효화한다고 합니다.

  • Extras

작업에 필요한 데이터를 키-값 쌍으로 보낼 수 있습니다.

  • Flags

Intent 클래스에 정의되어 있는 메타데이터입니다. 액티비티를 어떻게 실행할지 실행되고 어떻게 처리될지 등을 지시히라 수 있습니다.

참고

Implict Intent는 다음 정보가 추가할 수 있습니다.

  • Action
  • Category

Reference

https://google-developer-training.github.io/android-developer-fundamentals-course-concepts-v2/unit-1-get-started/lesson-2-activities-and-intents/2-1-c-activities-and-intents/2-1-c-activities-and-intents.html#aboutintents
https://developer.android.com/guide/components/intents-filters


Intent
Explict_Intent

← Previous Post Next Post