1. Intent
Intent는 Activity, Service, Broadcast, Contents Provider 컴포넌트를 시작시키는 message 객체이다.
일회성 시작인 경우 : startActivity(), startService()
서비스를 인터페이스 하는 경우 : bindService()
다른 앱도 수신해야하는 경우 : sendBroadcast, sendOrderedBroadcast()
명시적 인텐트 : 인텐트에 클래스 객체 컴포넌트 이름을 지정
var intent = Intent(this@MainActivity, SecondActivity::class.java)
암시적 인텐트 : 인텐트에 action, data, category 으로 유형을 명시
var intent = Intent(Intent.ACTION_DIAL, Uri.parse(data))
암시적 인텐트 사용 전 IntentFilter를 선언해야함
1) manifest 파일에 선언하는 방법
<activity android:name=”ShareActivity”>
<intent-filter>
<action android:name=”android.intent.action.SEND”/>
<category android:name=”android.intent.category.DEFAULT”/>
<data android:mimeType=”text/plain”/>
</intent-filter>
</activity>
2) 코드에서 동적으로 등록하는 방법
인텐트 이용
val intent = Intent()
intent.action = "ACTION_EDIT"
intent.data = Uri.parse("http://www.google.com")
startActivity(intent)
2. PendingIntent
특정시점에 수행하는 Intent.
다른 앱이 프로세스에 있을 때 Intent를 수행
PendingIntent.getActivity(Context, requestCode, Intent, Flag)
PendingIntent.getService(Context, requestCode, Intent, Flag )
PendingIntent.getBroadcast(Context, requestCode, Intent, Flag )
- Flag
FLAG_CANCEL_CURRENT : 이전에 생성한 PendingIntent 취소 후 새로 생성
FLAG_NO_CREATE : 이미 생성된 PendingIntent 가 있다면 재사용 (없으면 Null 리턴)
FLAG_ONE_SHOT : 해당 PendingIntent 를 일회성으로 사용
FLAG_UPDATE_CURRENT : 이미 생성된 PendingIntent 가 있다면, Extra Data 만 갈아끼움 (업데이트)
Android Kotlin Activity 액티비티 (0) | 2024.10.15 |
---|---|
Android Kotlin bindService LocalBinder (2) | 2024.09.25 |
Android Kotlin Context (3) | 2024.09.25 |
Android Kotlin Permission (0) | 2024.09.24 |
Android Kotlin Thread 와 Coroutine 과 Service (0) | 2024.09.24 |
댓글 영역