updating android activity ui from a service

18
인인인인 인인인인 인인인인인 UI 인인인인 SeongSik Choi

Upload: seongsik-choi

Post on 07-Jan-2017

1.554 views

Category:

Mobile


2 download

TRANSCRIPT

Page 1: Updating android activity UI from a service

인텐트를 이용하여서비스에서 UI 제어하기 SeongSik Choi

Page 2: Updating android activity UI from a service

Contents

■ 서비스 ?■ 문제점■ Intent?

- Explicit Intent - Implicit Intent

■ PendingIntent?■ Intent Falg■ 시연■ Reference

Page 3: Updating android activity UI from a service

서비스 ?

Page 4: Updating android activity UI from a service

서비스 ?

■ 백그라운드에서 동작하는 컴포넌트 (UI 를 갖지 않음 )■ 앱이 종료되어도 서비스는 계속 실행 (ex: MP3 재생 , push alarm)■ 자신의 호스트 프로세스의 기본 스레드에서 실행

Page 5: Updating android activity UI from a service

문제점1. 서비스 class 에서 MainActivity(UI class) 를 직접 제어 불가2. 푸시가 왔을 때 ,앱이 종료되었을 경우 푸시알림이 뜨도록하고 ,앱을 실행하고 있을 시엔 MainActivity 화면을 갱신하도록 구분

Page 6: Updating android activity UI from a service

문제점1. 서비스 class 에서 MainActivity(UI class) 를 직접 제어 불가2. 푸시가 왔을 때 ,앱이 종료되었을 경우 푸시알림이 뜨도록하고 ,앱을 실행하고 있을 시엔 MainActivity 화면을 갱신하도록 구분

Page 7: Updating android activity UI from a service

Intent

■ 일종의 메시지 객체■ 여러 구성요소들 사이의 통신에 사용■ 보통 Activity, Service, Broadcast 시작 및 전달 시 사용■ Explicit( 명시적 ) Intent 와 Implicit( 암시적 ) Intent 로 구분됨

Page 8: Updating android activity UI from a service

Intent■ Explicit( 명시적 ) Intent : 시작할 구성요소를 이름으로 지정

■ Implicit( 암시적 ) Intent : 기기에서 해당 작업을 수행할 수 있는 모든앱 호출가능

Page 9: Updating android activity UI from a service

문제점1. 서비스 class 에서 MainActivity(UI class) 를 직접 제어 불가2. 푸시가 왔을 때 ,앱이 종료되었을 경우 푸시알림이 뜨도록하고 ,앱을 실행하고 있을 시엔 MainActivity 화면을 갱신하도록 구분

Page 10: Updating android activity UI from a service

PendingIntent

■ 보류 인텐트■ Intent 객체를 랩핑하여 , 원하는 외래 어플리케이션에서 Intent 를 자체 Intent 처럼 사용하기 위한 용도■ 알림 , 위젯 , 알람으로 작업을 수행할때 Intent 를 실행하는 용도

Page 11: Updating android activity UI from a service

PendingIntent

Page 12: Updating android activity UI from a service

실행중인 프로세스 확인

Page 13: Updating android activity UI from a service

실행중인 프로세스 확인■ 앱이 종료되어 있을 경우 푸시가 왔을 때 ,

■ 앱이 실행 중일 경우 푸시가 왔을 때 ,

Page 14: Updating android activity UI from a service

미해결 문제■ 하나의 앱 내에 여러 Activity 간에는 구분이 힘듦

Page 15: Updating android activity UI from a service

Intent Flag■ Intent.FLAG_ACTIVITY_NEW_TASK

- 서비스에서 Activity 를 띄우려면 Task 를 생성해줘야함 (Task 가 Activity 를 관리 )■ Intent.FLAG_ACTIVITY_SINGLE_TOP

- 현재 Activity 가 다시시작되는 경우 인스턴스를 새로 생성하지 않고 , onNewIn-tent() 를 통해 기존 Activity 갱신

■ Intent.FLAG_ACTIVITY_CLEAR_TOP- Task 스택에서 해당 Activity 이상의 Activity 는 종료되고 , 해당 Activity 는 새로 생성 ,

Page 16: Updating android activity UI from a service

시연

Page 17: Updating android activity UI from a service

Reference

■ 앱 구성요소http://developer.android.com/intl/ko/guide/components/fundamentals.html#Components

■ 앱 구성요소 그림http://arabiannight.tistory.com/entry/ 안드로이드 Android-Service- 사용법

■ 서비스http://developer.android.com/intl/ko/guide/components/services.html

■ Intent, PendingIntenthttp://developer.android.com/intl/ko/guide/components/intents-filters.html

■ Intent Flag http://developer.android.com/intl/ko/guide/components/tasks-and-back-stack.html

Page 18: Updating android activity UI from a service

Thank You!!Q n A?