Intent Service 2017 3 1 Intent Activity Activity

  • Slides: 54
Download presentation
Intent & Service 2017년 3학년 1학기

Intent & Service 2017년 3학년 1학기

목차 Intent를 이용해 Activity 띄우기 Activity간 통신 Intent Filter Notification Service Alarm 2

목차 Intent를 이용해 Activity 띄우기 Activity간 통신 Intent Filter Notification Service Alarm 2

Intent

Intent

Intent 액티비티와 액티비티, 혹은 안드로이드 컴포넌트 간의 호출 및 정보 전달을 위한 객체 …

Intent 액티비티와 액티비티, 혹은 안드로이드 컴포넌트 간의 호출 및 정보 전달을 위한 객체 … do something Your. Activity … Android Intent(do something) Intent(result) My. Activity Intent(result) Your. Activity 4

Implicit intent 응용 Text를 전송할 때 Intent intent = new Intent(Intent. ACTION_SEND); intent. put.

Implicit intent 응용 Text를 전송할 때 Intent intent = new Intent(Intent. ACTION_SEND); intent. put. Extra(Intent. EXTRA_TEXT, "Text"); intent. set. Type("text/plain"); start. Activity(intent); 7

start. Activity … do something Sub. Activity … Android start. Activity(intent) Main. Activity on.

start. Activity … do something Sub. Activity … Android start. Activity(intent) Main. Activity on. Create(intent) Sub. Activity 10

start. Activity. For. Result & set. Result Main. Activity Sub. Activity start. Activity. For.

start. Activity. For. Result & set. Result Main. Activity Sub. Activity start. Activity. For. Result Set. Result() on. Activity. Result() Finish() 11

Activity간의 통신 Intent는 액티비티간에 인수와 리턴 값을 전달 가능 Bundle 타입의 Extras를 활용하여 이름과

Activity간의 통신 Intent는 액티비티간에 인수와 리턴 값을 전달 가능 Bundle 타입의 Extras를 활용하여 이름과 값의 쌍으로 된 임의 타입의 정보를 원하는 개수만큼 전달 할 수 있다. Intent put. Extra(String name, int value) Intent put. Extra(String name, String value) Intent put. Extra(String name, Boolean value) Key-Value형식으로, Key값(String name)이 겹치지 않는 한 자유롭게 전달 가능 Extras에 저장된 값들은 아래의 메서드로 꺼낸다. Int get. Int. Extra(String name, int default. Value); String get. String. Extra(String name); boolean get. Boolean. Extra(String name, boolean default. Value); 12

통신 예제(Sub. Activity) Sub. Activity. java …cont. -Sub. Activity를 호출한 인텐트 정보를 받아옴 -인텐트의

통신 예제(Sub. Activity) Sub. Activity. java …cont. -Sub. Activity를 호출한 인텐트 정보를 받아옴 -인텐트의 결과코드를 RESULT_CANCEL로 설정 -Sub. Activity 종료 15

암시적 호출(액션) 예제 activity_main. xml Main. Activity. java 18

암시적 호출(액션) 예제 activity_main. xml Main. Activity. java 18

Intent Filter 예제 (새 프로젝트) activity_main. xml Main. Activity. java 24

Intent Filter 예제 (새 프로젝트) activity_main. xml Main. Activity. java 24

Intent Filter 예제 (새 프로젝트) Android. Manifest. xml 아래 조건을 만족하는 인텐트를 받는 인텐트

Intent Filter 예제 (새 프로젝트) Android. Manifest. xml 아래 조건을 만족하는 인텐트를 받는 인텐트 필터 Action : View Category : Default (지정안함) Data scheme : http 25

Notification

Notification

Notification Notification. Builder § 알림에 대한 UI 정보와 작업을 지정하는 클래스 § 관련 Methods

Notification Notification. Builder § 알림에 대한 UI 정보와 작업을 지정하는 클래스 § 관련 Methods • set. Small. Icon(int icon) 알림의 아이콘을 지정할 Method 이미지 파일을 입력하여 그 id를 전달할 수도 있음 • set. Content. Title(Char. Sequence title) 알림의 제목을 지정할 Method • Set. Content. Text(Char. Squence text) 알림의 구체적 내용을 지정할 Method 30

Notification 31

Notification 31

Notification 32

Notification 32

Service

Service

Service 서비스의 Life Cycle 37

Service 서비스의 Life Cycle 37

Service 서비스 만들기 § Ibinder on. Bind(Intent intent) • § 다른 컴포넌트가 bind. Service()를

Service 서비스 만들기 § Ibinder on. Bind(Intent intent) • § 다른 컴포넌트가 bind. Service()를 호출하여 본 서비스와 연결을 시도할 경우 호출됨 on. Start. Command(Intent intent, int flags, int start. Id) 40

Service 예제 코드 (My. Service. java / Main. Activity. java) 42

Service 예제 코드 (My. Service. java / Main. Activity. java) 42

Service 예제 코드 실행 결과 § Android Device Monitor의 Log. Cat을 통해서 동작을 확인함

Service 예제 코드 실행 결과 § Android Device Monitor의 Log. Cat을 통해서 동작을 확인함 43

Alarm

Alarm

Alarm Alarm. Manager § 알람을 발생시키거나 취소할 수 있는 클래스 § 관련 Methods •

Alarm Alarm. Manager § 알람을 발생시키거나 취소할 수 있는 클래스 § 관련 Methods • set (int type, long trigger. At. Time, Pending. Intent operation) 일회성 알람을 발생시키는 Method • set. Repeating (int type, long trigger. At. Time, long interval, Pending. Intent operation) 반복적인 알람을 발생시키는 Method long interval에 전달된 시간만큼 반복하여 알람을 수행 47

Alarm § set. Inexact. Repeating (int type, long trigger. At. Time, long interval, Pending.

Alarm § set. Inexact. Repeating (int type, long trigger. At. Time, long interval, Pending. Intent operation) Alarm. Manager에 정의된 상수 중 하나를 사용하여 반복된 알람을 수행 set. Repeating( )처럼 정확한 간격으로 반복을 수행하진 않음 대신 배터리 효율이 뛰어남 § cancel (Pending. Intent operation) 알람을 취소하는 Method 48

Alarm 예제 코드 (Main. Activity. java) (1) 51

Alarm 예제 코드 (Main. Activity. java) (1) 51

Alarm 예제 코드 (Main. Activity. java) (2) 52

Alarm 예제 코드 (Main. Activity. java) (2) 52

Alarm 예시 (Alarm. Receiver. java) 53

Alarm 예시 (Alarm. Receiver. java) 53