Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
전자공학 실험 2 1 WEEK14: ANDROID PROGRAMMING II Fall, 2014 건국대 전자공학부 Notice: 주별 강의/실습/HW 내용 2 Week Date 강의주제 1 09월 03일 Orientation 2 09월 10일 추석 3 09월 17일 Using Objects 4 09월 24일 Classes, Objects 5 10월 01일 6 Homework 실습과제 Handouts Lab1 Lecture0 Lab2 Lecture1 HW1 Lab3 Lecture2 Inheritance, Interface HW2 Lab4 Lecture3 10월 08일 Exception Handling, Thread HW3 Lab5 Lecture4 7 10월 15일 File, I/O Streams - Byte Stream HW4 Lab6 Lecture5 8 10월 22일 Mid-term Exam. 9 10월 29일 File, I/O Streams-Char. Stream Lab9 Lecture9 10 11월 05일 Swing & Event Handling Lab10 Lecture10 11 11월 12일 Java Network Programming I Lab11 Lecture11 12 11월 19일 Java Network Programming II Lab12 Lecture12 13 11월 26일 Android Programming I Lab13 Lecture13 14 12월 03일 Android Programming II Lab14 Lecture14 15 12월 10일 Android Programming III Lab15 Lecture15 16 12월 17일 Final Exam 실습 결과보고서 제출일 3 Lab.14-1~8 : 주어진 대로 실행해 보고 단계별 중요한 개념과 사실들을 정리하시오 실제 안드로이드 폰에서 실행해보고 결과화면 캡쳐 이미지 첨부 Due Dec . 10 Lab.14-1~4 : 당일 (Dec. 3) 개별 demo. Lab.14-5~8 : 다음 주 (Dec. 10) 개별 demo. 12/3 실습 좌석 배치 (전주와 동일) 4 성명 실험조 좌석번호 성명 실험조 좌석번호 김지혜 5 1 신승훈 3 13 적아휘 7 2 조현민 8 14 원용범 4 3 김창섭 8 15 이서우 6 4 임준형 3 16 박정훈 4 5 유홍식 9 17 이준엽 9 6 윤치열 5 18 최재은 1 7 문찬용 7 19 주성호 2 8 나지원 6 20 박구병 7 9 이한용 8 21 민인기 5 10 이채준 6 22 이윤호 2 11 정치영 9 23 이희준 4 12 윤재형 1 24 5 Topics To Be Covered Action Bar Intent Activity Intent Filter Activity Life Cycle 6 사용자 인터페이스 기초 The following subjects, mainly concerned with UI, are not extensively covered in this lecture, however, still it is your responsibility to study the subjects on your own, if required for performing your practices ! Layout, View, View Group, Widgets, Fragments 뷰와 뷰그룹 UI를 작성하는 절차 1. 뷰그룹을 생성한다. 2. 필요한 뷰를 추가한다. 3. 액티비티 화면으로 설정한다. UI를 작성하는 3가지 방법 XML로 UI 작성 XML로 UI 작성 코드로 뷰를 생성하는 방법 XML과 코드를 동시에 사용하는 방법 뷰 View 클래스는 모든 뷰들의 부모 클래스이다. View 클래스가 가지고 있는 필드나 메소드는 모든 뷰에 서 공통적으로 사용할 수 있다. 뷰의 필드와 메소드 id 뷰의 식별자 뷰의 위치와 크기 색상 16진수로 투명도와 빛의 3원색인 RGB값을 표시 마진과 패딩 패딩이란 뷰의 경계와 뷰의 내용물 사이의 간격 마진이란 자식 뷰 주위의 여백 마진과 패딩 paddingLeft, paddingRight, paddingTop, paddingBottom layout_marginLeft, layout_marginRight, layout_marginTop, layout_marginBottom 마진과 패딩의 예 텍스트뷰 에디트 텍스트 이미지뷰 아이콘과 같은 이미지들을 간단히 표시하는 데 사용 안드로이드에서 이미지 사용 이미지를 drawable 폴더로 드래그한다. 이미지뷰 26 레이아웃 레이아웃 뷰들을 화면에 배치하는 방법 레이아웃의 종류 Time is short! 여러분의 몫입니다 29 Lab14-1. 앱실행시 액션바 보이게 하기 ActionBarTest 프로젝트 생성 “appcompat_v7”프로젝트 생성되지 않게 하기 30 새 프로젝트 생성시 하위 버젼과의 호환성 유지를 위해 자동으로 생성 간혹 예기치 못한 여러 문제를 야기할 수 있다. 이 프로젝트가 생성되지 않도록 하려 면 프로젝트 생성시 minimum SDK를 4.0 이 상으로 설정하면 됨 31 안드로이드 아이콘 패키지 내려받기 32 Visit http://developer.android.com/design/downloads/index. html And download and unpack “Action Bar Icon Pack” res 폴더에 아이콘 이미지 넣기 33 다운받은 이미지중에서 ic_action_call.png, ic_action_search.png, ic_action_refresh.png 를 프로젝트 drawable-mdpi폴더에 복사 (패키지 core 부분) Res\menu\main.xml 수정 34 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.hello.MainActivity" > <item android:id="@+id/item_refresh" android:icon="@drawable/ic_action_refresh" android:showAsAction="ifRoom" android:title="Refresh"/> <item android:id="@+id/item_search" android:icon="@drawable/ic_action_search" android:showAsAction="ifRoom" android:title="Search"/> <item android:id="@+id/item_save" android:icon="@drawable/ic_action_call" android:showAsAction="ifRoom" android:title="Save"/> <item android:id="@+id/action_settings" android:showAsAction="never" android:title="Settings"/> </menu> Activity 파일내 onCreateOptionsMenu 재정의 35 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); return true; } onOptionsItemSelected() 재정의 36 @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.item_refresh: Toast.makeText(this, "Refreshing 메뉴 선택", Toast.LENGTH_SHORT).show(); break; case R.id.item_search: Toast.makeText(this, “Search 메뉴 선택", Toast.LENGTH_SHORT).show(); break; case R.id.item_save: Toast.makeText(this, " Saving 메뉴 선택", Toast.LENGTH_SHORT).show(); makeToast("Saving 메뉴 선택"); break; } } return true; 앱 실행 결과화면 37 38 안드로이드의 이벤트 처리 Event Handling 안드로이드의 이벤트 처리 방법 1. 이벤트 처리 객체를 생성하여 컴포넌트에 등록 Java 프로그래밍에서 자주 쓰던 방식 내부 클래스 정의 또는 익명 클래스 사용 2. XML을 이용한 이벤트 처리 가장 간편 3. Listener 인터페이스를 액티비티 클래스에 구현. 4. View 클래스를 상속하는 방법 View 클래스 자체의 이벤트 처리 callback 메소드 이용 1. 이벤트 처리 객체를 사용하는 방법 액티비티 내에서 리스너 객체를 생성한 후 뷰에 장착 리스너 클래스를 내부 클래스로 정의 리스너 클래스를 익명 클래스로 정의 가장 많이 사용되는 방법! 리스너 클래스를 내부 클래스로 정의 버튼에 붙은 리스너 객체가 이벤트를 처리한다. 이벤트 리스너 43 Lab14-2. 리스너 클래스를 내부 클래스로 정의 버튼을 누르면 메시지를 Toast하는 앱 ButtonEvent1 프로젝트 생성 44 45 activity_main.xml을 다음과 같이 변경 46 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="버튼을 눌러 보세요" /> </LinearLayout> MainActivity.java를 다음과 같이 변경 47 public class MainActivity extends Activity { class MyListener implements OnClickListener { public void onClick(View v){ Toast.makeText(getApplicationContext(), "버튼이 눌렸어요", Toast.LENGTH_LONG).show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); MyListener buttonListener = new MyListener(); button.setOnClickListener(buttonListener); } ….. } 실행결과 48 콜백 메소드를 재정의할 때 편리한 기능 [Source] → [Override/Implements Methods…] 사용! 50 Lab14-3. 익명 클래스로 이벤트를 처리 버튼을 누르면 메시지를 Toast하는 앱 ButtonEvent2 프로젝트 생성 MainActivity.java를 다음과 같이 변경 ... public class ButtonEvent2Activity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(getApplicationContext(), "버튼이 눌려졌습니다", Toast.LENGTH_SHORT).show(); } }); } } 익명 클래스 클래스 몸체는 정의되지만 이름이 없는 클래스이다. 익명 클래스는 클래스를 정의하면서 동시에 객체를 생 성하게 된다. class ClickListener implements OnClickListener { ... } obj = new ClickListener(); obj = new OnClickListener() { .... }; 코드 분석 ... public class ButtonEvent2Activity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { 익명 클래스 사용 super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(getApplicationContext(), "버튼 눌려졌습니다", Toast.LENGTH_SHORT).show(); } }); } } 54 Lab14-4. XML을 이용한 이벤트 처리 버튼을 누르면 메시지를 Toast하는 앱 ButtonEvent3 프로젝트 생성 레이아웃 파일 내용을 다음과 같이 변경 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height=“match_parent" android:orientation="vertical" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="myClickListener" android:padding="10dp" android:text="버튼을 눌러보세요" /> </LinearLayout> 이 버튼을 클릭하면 호출 되는 메소드 이름을 적어 준다. 액티비티 파일 내용을 다음과 같이 변경 ... public class ButtonEvent4Activity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { XML에서 호출된다. super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void myClickListener(View target) { Toast.makeText(getApplicationContext(), "버튼이 눌려졌습니다", Toast.LENGTH_SHORT).show(); } } 57 Lab14-5. Listener 인터페이스를 액티비티 클래스에 구현하는 방법 버튼을 누르면 메시지를 Toast하는 앱 ButtonEvent4 프로젝트 생성 액티비티 파일 내용을 다음과 같이 변경 public class MainActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(this); } public void onClick(View v) { Toast.makeText(getApplicationContext(), "버튼이 눌려졌습니다", Toast.LENGTH_SHORT).show(); } } (이벤트 처리 마지막 방법은 생략) ... class MyView extends View { int key; String str; public MyView(Context context) { super(context); setBackgroundColor(Color.YELLOW); } public boolean onKeyDown(int keyCode, KeyEvent event) { str = "" + keyCode; invalidate(); return super.onKeyDown(keyCode, event); } @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); canvas.drawText("키코드 = " + str, 0, 20, paint); } } 예제 public class MyViewEventActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyView w = new MyView(this); w.setFocusable(true); setContentView(w); } } … 액티비티 62 Activity An activity represents a single screen with a user interface. For example, an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email app, each one is independent of the others. As such, a different app can start any one of these activities (if the email app allows it). For example, a camera app can start the activity in the email app that composes new mail, in order for the user to share a picture. 4가지의 중요한 개념 애플리케이션(application) 액티비티(activities) 액티비티 스택(activity stack) 태스크(task) 애플리케이션 한 개 이상의 액티비티들로 구성된다. 액티비티들은 애플리케이션 안에서 느슨하게 묶여 있다. 액티비티 애플리케이션을 구성하는 빌딩 블록 태스크 스택에 있는 액티비티 액티비티 스택 Back 키를 누르면 현재 액티비티를 제거하고 이전 액티 비티로 되돌아 간다. 사용자가 방문한 액티비티들은 어딘가에 기억 멀티태스킹 동시에 여러 태스크를 실행 현재의 태스크를 배경(background)으로 보내고 다른 태 스크를 전경(foreground)에서 시작할 수 있다. HOME 키를 누르면 멀티 태스킹이 시작된다. 인텐트 71 Intent A messaging object you can use to request an action from another app component. 72 Intent An object that provides runtime binding between separate components (such as two activities). The Intent represents an app’s "intent to do something." 인텐트 각각의 화면은 별도의 액티비티로 구현된다. 하나의 액티비티(화면)에서 다른 액티비티(화면)로 전환 하려면 어떻게 하여야 하는가? 인텐트 다른 액티비티를 시작하려면 액티비티의 실행에 필요한 여러 가지 정보들을 보내주어야 한다. 정보를 인텐트에 실어서 보낸다. 인텐트의 종류 명시적 인텐트(explicit intent) “애플리케이션 A의 컴포넌트 B를 구동시켜라“와 같이 명확하게 지정 암시적 인텐트(implicit intent) “지도를 보여줄 수 있는 컴포넌트이면 어떤 것이라도 좋다” Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be ru 76 명시적 인텐트 Explicit Intent 77 Explicit Intent Explicit Intents have specified a component, which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application. 명시적 인텐트 실행하고자 하는 액티비티의 이름을 적어 준다. Intent intent = new Intent(this, NextActivity.class); startActivity(intent); 79 Lab14-6. 명시적 인텐트 사용해 보기 두 개의 액티비티로 이루어진 애플리케이션 을 작성 ExplicitIntent라는 프로젝트 생성 명시적 인텐트 사용해 보기 여기서 두 개의 액티비티로 이루어진 애플리케이션을 작성하여 보자. 첫 번째 액티비티는 Activity1, 두 번째 액티비티는 Activity2라고 하자. 레이아웃 파일 layout1.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="여기는 액티비티1입니다." /> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="이미지 표시 액티비티 열기" /> </LinearLayout> 레이아웃 파일 layout2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="여기는 액티비티2입니다" /> <ImageView android:id="@+id/imageView1" android:layout_width="135dp" android:layout_height="248dp" android:src="@drawable/ic_launcher" /> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="닫기" /> </LinearLayout> Activity1.java ... public class Activity1 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); Button b = (Button)findViewById(R.id.Button01); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Activity1.this, Activity2.class); startActivity(intent); } }); } } Activity2.java public class Activity2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout2); Button b = (Button)findViewById(R.id.Button01); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); } } 메니페스트 파일에 구성요소 등록 ... <activity android:name=".Activity1" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="Activity2" android:label="Activity2"></activity> ... 실행 결과 Question: 87 만약 Activity2에서 finish() 호출 대신 인텐트 객체 생성 을 통해 Activity1을 실행한다면 어떻게 될까? b.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Activity2.this, Activity1.class); startActivity(intent); } }); 88 인텐트를 통해 데이터 주고받기 액티비티에서 결과받기 ReQCode 값을 저장하고, 값을 읽는 메소드 91 Lab14-7. 인텐트를 통해 데이터 주고받기 서브 액티비티에서 입력된 문자열을 메인 액티비 티에서 출력하는 앱 작성 ActivityForResult라는 프로젝트 생성 인텐트를 통해 데이터 주고받기 레이아웃 파일 main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="match_parent" android:text="서브 액티비티로부터 문자열 반환받기“ android:layout_height="wrap_content" android:id="@+id/button"> </Button> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="반환된 문자열“ android:id="@+id/textView1"> </TextView> <TextView android:layout_height="wrap_content" android:text="____________________" android:id="@+id/text" android:layout_width="match_parent"> </TextView> </LinearLayout> 레이아웃 파일 sub.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > … <EditText android:id="@+id/edit" android:layout_width="match_parent" android:layout_height="wrap_content" > <requestFocus></requestFocus> </EditText> 레이아웃 파일 sub.xml <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" > <Button android:id="@+id/button_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="입력완료" > </Button> <Button android:id="@+id/button_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="취소" > </Button> </LinearLayout> 매니페스트 파일 수정 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" ... <application ... <activity android:name="kr.co.company.activityforresult.MainActivity" android:label="@string/app_name" > ... </activity> <activity android:name=".SubActivity" android:label="SubActivity" > </activity> </application> </manifest> Mainactivity.java ... public class MainActivity extends Activity { static final int GET_STRING = 1; TextView text; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button); text = (TextView) findViewById(R.id.text); button.setOnClickListener(new OnClickListener() { // @Override public void onClick(View arg0) { Intent in = new Intent(MainActivity.this, SubActivity.class); startActivityForResult(in, GET_STRING); } }); } Mainactivity.java ... @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == GET_STRING) { if (resultCode == RESULT_OK) { text.setText(data.getStringExtra("INPUT_TEXT")); } } } } Subactivity.java ... public class SubActivity extends Activity { EditText edit; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sub); edit = (EditText) findViewById(R.id.edit); Button button_ok = (Button) findViewById(R.id.button_ok); button_ok.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("INPUT_TEXT", edit.getText().toString()); setResult(RESULT_OK, intent); finish(); } }); Subactivity.java Button button_cancel = (Button) findViewById(R.id.button_cancel); button_cancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { setResult(RESULT_CANCELED); finish(); } }); } } 실행 결과 102 암시적 인텐트 Implicit Intent 103 Implicit Intent Implicit intents do not declare the class name of the component to start, but instead declare an action to perform. The action specifies the thing you want to do, such as view, edit, send, or get something. Intents often also include data associated with the action, such as the address you want to view, or the email message you want to send. Depending on the intent you want to create, the data might be a Uri, one of several other data types, or the intent might not need data at all. 암시적인 인텐트 어떤 작업을 하기를 원하지만 그 작업을 담당하는 컴포 넌트의 이름을 명확하게 모르는 경우에 사용 암시적 인텐트의 형식 To initiate a phone call using the Uri data to specify the telephone number: Uri number = Uri.parse("tel:5551234"); Intent callIntent = new Intent(Intent.ACTION_DIAL, number); startActivity(callIntent); View a web page: Uri webpage = Uri.parse("http://www.android.com"); Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage); startActivity(webIntent); 액션의 종류 상수 타겟 컴포넌 액션 트 ACTIN_VIEW 액티비티 데이터를 사용자에게 표시한다. ACTION_EDIT 액티비티 사용자가 편집할 수 있는 데이터를 표시한다. ACTION_MAIN 액티비티 태스크의 초기 액티비티로 설정한다. ACTION_CALL 액티비티 전화 통화를 시작한다. ACTION_DIAL 액티비티 전화 번호를 누르는 화면을 표시한다. 107 Lab14-8. 암시적 인텐트 사용해 보기 ImplicitIntent라는 프로젝트 생성 암시적 인텐트 사용해 보기 사용자 인터페이스 <?xml version="1.0" encoding="utf‐8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/call" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:text="전화걸기" > </Button> <Button android:id="@+id/map" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:text="지도보기" > </Button> 사용자 인터페이스 <Button android:id="@+id/web" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:text="웹브라우저" > </Button> <Button android:id="@+id/contact" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:text="연락처보기" > </Button> </LinearLayout> 암시적 인텐트 사용해 보기 public class ImplicitIntentActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onClick(View view) { Intent intent = null; switch (view.getId()) { case R.id.web: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); break; case R.id.call: intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:(+82)12345789")); break; 암시적 인텐트 사용해 보기 case R.id.map: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:37.30,127.2?z=10")); break; case R.id.contact: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/")); break; } if (intent != null) { startActivity(intent); } } } 매니페스트 파일 수정 ... <uses-permission android:name="android.permission.CALL_PHONE" > </uses-permission> <uses-permission android:name="android.permission.CAMERA" > </uses-permission> <uses-permission android:name="android.permission.READ_CONTACTS" > </uses-permission> <uses-permission android:name="android.permission.INTERNET"/> ... 실행 결과 인텐트 필터 Intent Filter 인텐트 필터 컴포넌트는 자신들이 처리할 수 있는 인텐트의 종류를 인텐트 필터에 기록한다. 인텐트 필터 액티비티 생애주기 Activity Life Cycle 액티비티 생애주기 실행 상태(resumed, running): 액티비티가 전경에 위치 하고 있으며 사용자의 포커스를 가지고 있다. 일시멈춤 상태(paused): 다른 액티비티가 전경에 있으 며 포커스를 가지고 있지만 현재 액티비티의 일부가 아 직도 화면에서 보이고 있는 상태이다. 정지 상태(stopped): 액티비티는 배경에 위치한다. 액티비티 상태 액티비티 객체 생성 단계 일시 멈춤 상태 정지되었다가 다시 실행하는 경우 중요한 콜백 메소드 onCreate() 액티비티가 생성되면서 호출 중요한 구성요소들을 초기화 onPause() 사용자가 액티비티를 떠나고 있을 때, 이 메소드가 호출 그 동안 이루어졌던 변경사항을 저장