인텐트
- Intent의 첫번째 매개변수는 호출하는 액티비티를 나타내고, 두번째 매개변수에는 호출할 액티비티를 나타냅니다.
그리고 Intent하는 두 액티비티는 모두 manifest에 등록되어 있어야한다!!!!
1 2 3 | Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); | cs |
인텐트(Intent)는 컴포넌트에 액션, 데이터 등을 전달하는 메시지 객체이다. 인텐트 객체의 구성 요소는 다음과 같다.
▶ Action (액션): 수행할 액션 이름(ACTION_DIAL)
▶ Data (데이터): 수행할 데이터의 URI(tel:)
▶ Category (카테고리): 수행할 액션에 대한 추가적인 정보
▶ Type (타입): 수행할 인텐트 데이터의 명시적인 타입(MIME 타입) (video/mpeg)
▶ Component name (컴포넌트 이름): 대상 컴포넌트의 완전한 클래스 이름
▶ Extras (추가 정보): 인텐트를 다루는 컴포넌트에 추가적으로 전달할 한 쌍의 키 / 값
컴포넌트 활성화 시점
컴포넌트 | 활성화 시점 |
Activity | 인텐트에 의해 활성화 |
Service | 인텐트에 의해 활성화 |
Broadcast Receiver | 인텐트에 의해 활성화 |
Content provider | ContentResolver에 의해 활성화 |
컴포넌트 활성화
컴포넌트 | 활성화 |
Activity | Context.startActivity() Activity.startActivityForResult()에 인텐트 객체를 전달해서 활성화 |
Service | Context.startService()에 인텐트 객체를 전달해서 활성화 |
Broadcast Receiver | Context.sendBroadcast() Context.sendOrderedBroadcast() Context.sendStickyBroadcast()에 인텐트 객체를 전달해서 활성화 |
인텐트 필터
인텐트 필터(Intent Filter)는 특정 인텐트를 받을지 말지를 정의하는 역할을 수행하며, 이를 통해 컴포넌트의 특징이 정해진다. 예를 들어, 인텐트 필터에 android.intent.action.MAIN을 선언하고 다음에 android.intent.category.HOME을 선언하면, 해당 컴포넌트는 홈 애플리케이션이 되어 디바이스가 시작될 때 자동으로 시작될 수 있는 애플리케이션이 된다. 인텐트 필터를 구성하는 요소는 인텐트에 작성할 수 있는 요소들과 동일하다.
- 앱 컴포넌트는 인텐트 필터를 가질 수 있고, 안드로이드는 인텐트 필터를 이용하여 어떤 앱 컴포넌트에 암시적 인텐트를 전달할지를 결정.
- 명시적 인텐트에는 클래스 이름이 설정되어 있어 무엇을 실행할지가 명확함.
- - 묵시적 인텐트는 클래스 이름 대신 액션 이름이 설정됨.
(액션 이름만으로는 어떤 앱 컴포넌트를 실행할지가 명확하지 않다.)
1 2 3 4 5 6 7 8 9 10 | private void fobidden_activity() { Intent intent = new Intent(); intent.setAction("android.intent.action.MAIN"); intent.addCategory("android.intent.category.HOME"); intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); startActivity(intent); } | cs |
setAction
Intent setAction (String action)
Set the general action to be performed.
Parameters | |
---|---|
action | String : An action name, such as ACTION_VIEW. Application-specific actions should be prefixed with the vendor's package name. |
Returns | |
---|---|
Intent | Returns the same Intent object, for chaining multiple calls into a single statement. |
ACTION_MAIN
String ACTION_MAIN
Activity Action: Start as a main entry point, does not expect to receive data.
Input: nothing
Output: nothing
Constant Value: "android.intent.action.MAIN"
addCategory
Intent addCategory (String category)
Add a new category to the intent. Categories provide additional detail about the action the intent performs. When resolving an intent, only activities that provide all of the requested categories will be used.
Parameters | |
---|---|
category | String : The desired category. This can be either one of the predefined Intent categories, or a custom category in your own namespace. |
Returns | |
---|---|
Intent | Returns the same Intent object, for chaining multiple calls into a single statement. |
addFlags
Intent addFlags (int flags)
Add additional flags to the intent (or with existing flags value).
Parameters | |
---|---|
flags | int : The new flags to set. |
Returns | |
---|---|
Intent | Returns the same Intent object, for chaining multiple calls into a single statement. |
CATEGORY_HOME
String CATEGORY_HOME
This is the home activity, that is the first activity that is displayed when the device boots.
Constant Value: "android.intent.category.HOME"
int | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS If set, the new activity is not kept in the list of recently launched activities. |
int | FLAG_ACTIVITY_FORWARD_RESULT If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity. |
int | FLAG_ACTIVITY_NEW_TASK If set, this activity will become the start of a new task on this history stack. |
int | FLAG_ACTIVITY_PREVIOUS_IS_TOP If set and this intent is being used to launch a new activity from an existing one, the current activity will not be counted as the top activity for deciding whether the new intent should be delivered to the top instead of starting a new on |
int | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task. |
출처 : https://developer.android.com/reference/android/content
'Programming > Android' 카테고리의 다른 글
AsyncTask (0) | 2016.08.26 |
---|---|
AccessibilityService (0) | 2016.08.26 |
어플 패키지명 (0) | 2016.08.25 |
ProgressDialog 와 Toast (0) | 2016.08.25 |
HttpURLConnection (0) | 2016.08.25 |