Download presentation
Presentation is loading. Please wait.
Published byPatricia Bishop Modified over 8 years ago
1
Speech Service & client(Activity) 2013.10.16 오지영
2
Android Application Application Package Activity BroadCast Receiver Content Provider Service
3
Android Service Service 안드로이드 Application 을 구성하는 컴포넌트 중 하나 Activity 처럼 사용자와 상호작용 하는 컴포넌트가 아니라 Background 에서 동작하 는 컴포넌트 Activity 화면에서 동작뿐만 아니라 Activity 가 종료되어 있는 상태에서 동작하기 위 해 만들어진 컴포넌트 예 :MP3 플레이어 Service 시작과 중지 함수 startService(Intent Service) stopService(Intent Service) 두 함수는 Context class 소속 (Context class 다음 장에서 소개 )
4
Context class Overview Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
5
Context class – startService, stopService Method public abstract ComponentName startService(Intent service) Request that a given application service be started parameters service : Identifies the service to be started. The Intent may specify either an explicit component name to start, or a logical description (action, category, etc) to match an IntentFilter published by a service. Additional values may be included in the Intent extras to supply arguments along with this specific start callIntentFilter Returns If the service is being started or is already running, the ComponentName of the actual service that was started is returned; else if the service does not exist null is returned.ComponentName public abstract boolean stopService(Intent service) Request that a given application service be stopped. If the service is not running, nothing happens. Otherwise it is stopped. Note that calls to startService() are not counted -- this stops the service no matter how many times it was started. Parameters service : Description of the service to be stopped. The Intent may specify either an explicit component name to start, or a logical description (action, category, etc) to match an IntentFilter published by a service.IntentFilter Returns If there is a service matching the given Intent that is already running, then it is stopped and true is returned; else false is returned.
6
Service 처리과정 Service 주기 Activity 에서 startService() 를 호출하면 Service 의 onCreate() -> onStartCommand() 순서대로 처리
7
Service 예제 : Music Player Service-Project, Activity 구현한 서비스 mp3 를 play, stop 함
8
Service 예제 : Music Player Service- AndroidManifest.xml 프로젝트의 AndroidManifest 에 service 를 등록
9
Service 예제 : Music Player Service-MainActivity.java Activit 에서 service 를 호출
10
Service 예제 : Music Player Service-MyService.java
12
Broadcast Receiver BroadcastReceiver Component 들 간에 메시지를 전달
13
Context class – sendBroadcast Method public abstract void sendBroadcast(Intent intent) Broadcast the given intent to all interested BroadcastReceivers. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run. No results are propagated from receivers and receivers can not abort the broadcast Parmaters intent : The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
14
Toast class Overview A toast is a view containing a quick little message for the user. The toast class helps you create and show those. When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved public Method public static Toast makeText(Coontext, CharSequence text, int duration) Make a standard toast that just contains a text view. Parameters context : The context to use. Usually your Application or Activity object. text : The text to show. Can be formatted text. duration : How long to display the message. Either LENGTH_SHORT or LENGTH_LONG.
16
Broadcast Receiver ( 방송하는 패키지 )
17
Broadcast Receiver- 정적 Receiver Receiver 를 고정해서 등록하고 원하는 방송에 반응하는 Receiver
18
Broadcast Receiver- 정적 Receiver 결과
19
Broadcast Receiver- 동적 Receiver AndroidManifest.xml 에 등록하지 않음
20
IntentFilter 를 생성하여 방송과 매칭될 Action 과 데이터를 등록 BroadcastReceiver 객체를 생성, onReceiver() 함수 구현 방송이 들어오면 onReceiver() 함수가 호출 BroadcastReciver 객체를 등록
21
Broadcast Receiver- 동적 Receiver 결과
23
Broadcast Receiver- 동적 Receiver 동적 리시버의 특징 자신을 등록한 Component 의 생명 주기가 끝나명 사라짐 unregisterReceiver() 함수 : 등록 해제 Component 내에 Receiver 소스가 존재하므로 Activity 내에 모든 맴버 객체에 접근 가능 정적 Receiver 의 경우 특정 Component 에 포함되어 있지 않으므로 멤버변수에 접근 불가능
25
처리 과정 RecognitionService(background) servicename : voice.wins.or.kr.service app Main Acitivity BroadcastReceiver name : restReceiver.wins.or.kr.service 1. startService(intent) 2. Recognition 3. intent.putExtra(value) 4. sendBroadcast(intent) 5. intent.getExtras() 6. send data to mainActivity ⓐ ⓑ ⓒ
26
ServiceClient-project, AndroidManifest.xml 프로젝트의 AndroidManifest 에 Receiver 등록
27
ServiceClient-MainActivity.java onResume() / onPause() Activity 위에 다른 Activity 가 올라왔거나 focus 를 읽었거나 다시 얻을 때 불림 onStart() / onStop() Activity 가 완전히 화면을 벗어날때 예 : 홈키를 눌러 홈화면으로 이동
28
ServiceClient-MainActivity.java Service 호출
29
ServiceClient-TestReceiver.java
30
testService-project, AndroidManifest.xml
31
RecognitionService-VoiceRecognitionService.java
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.