SlideShare a Scribd company logo
Service Instance 개수
Activity는 여러 Instance가 생성되는 것으로 알고 있습니다.
그런데, Service도 요청 때 마다 여러 Service Instance가 생길까요?
Instance 수에 대한 요약
특히나 IntentService는?
IntentService는 Intent를 전달 받을 때 마다, 해당 Intent를 처리하도록
특화되어 있는 Service 중 하나입니다.
예를 들어서, 특정 데이터를 전송하고, 해당 데이터를 저장을 하는 작업과
같은 작업을 IntentService를 통해서 구현할 수 있습니다.
IntentService에 대한 자세한 내용:
http://developer.android.com/reference/android/app/IntentService.html
이 Service 경우 자체가 가지는 특수성에 따라서,
Intent에 대해서 동시 다발적으로 처리가 수행이 되는지가 중요합니다.
이에 대해서 알아보도록 합니다.
IntentService Overview
IntentService is a base class for Services that handle asynchronous
requests (expressed as Intents) on demand. Clients send requests
throughstartService(Intent) calls; the service is started as needed,
handles each Intent in turn using a worker thread, and stops itself
when it runs out of work.
This "work queue processor" pattern is commonly used to offload tasks from
an application's main thread. The IntentService class exists to simplify this
pattern and take care of the mechanics. To use it, extend IntentService and
implement onHandleIntent(Intent). IntentService will receive the Intents,
launch a worker thread, and stop the service as appropriate.
All requests are handled on a single worker thread -- they may take as
long as necessary (and will not block the application's main loop), but only
one request will be processed at a time.
결론은!
IntentService는 Intent를 가지고 여러 번 호출이 되더라도,
한 번에 하나씩 요청이 인입된 순서에 따라서 처리를 진행합니다.
처리할 Intent가 없으면, Service는 사라지고
신규 Intent가 도착하여 처리할 사항이 있으면 Service가 1개 신규 생성됩니다.
만약 Intent가 여러 개가 쭈욱 밀려 있으며,
처음 생성된 Intent가 모든 Intent를 순차적으로 처리를 하게 됩니다.
즉, IntentService는 하나의 Instance가 순차적으로 처리를 진행합니다.
테스트 진행
Service start가 호출될 때마다 Instance가 생성되어
호출이 되게 되면,
Test time이 호출되는 내역이 번갈아 나타날 것이고
Instance 하나가 나타나면 순차적으로 나타날 것입니다.
테스트 결과
수행 1. 3회 연달아 서비스 호출
수행 2. 3회 처리 후 서비스 2회 연달아 호출
Thread ID.
처리할 작업이 없어지니 사라지고
새 처리 작업이 발생되니 새로 생성 확인
요청이 Multi가 아닌 Single로
순차적으로 처리됨을 확인
덧붙이자면~
Service에 대해서 동일한 테스트를 한 결과.
Instance는 하나만 생성이 되고, Service가 제공이 됨이 확인되었습니다.
그렇지만, Service는 InstanceService와 별도로 Thread 하나가
메모리 상태에 꾸준히 떠 있는 데몬 형태와 같이 구동을 함을 확인 했습니다.
동일하게 3회/2회 연달아서 테스트. Thread ID 동일 확인

More Related Content

PDF
[ES6] 2. arrow function
PDF
12 service
PDF
05 pending intent
PDF
10 view orientation_change
PDF
06 activity stack and back, flag
PDF
08 fragment 태블릿 대응
PDF
Wot(daliworks) 20131113
PDF
NIPA SW Insight Report '13.08
[ES6] 2. arrow function
12 service
05 pending intent
10 view orientation_change
06 activity stack and back, flag
08 fragment 태블릿 대응
Wot(daliworks) 20131113
NIPA SW Insight Report '13.08

More from 운용 최 (20)

PDF
Agile Spirit Base On The Book "Agile Samuari"
PDF
Uml intro 1
PDF
Uml intro 0
PDF
21 application and_network_status
PDF
20 handler and_async_task
PDF
18 안드로이드 리스트뷰_속도향상
PDF
19 나만의 view 만들기
PDF
17 adapter view & db
PDF
16 데이터 저장과 사용
PDF
15 content provider
PDF
14 broad castreceiver
PDF
11 tablet 대응 가이드
PDF
09 android keyboard & layout
PDF
08 font size
PDF
07 다양한 device_대응_방법
PDF
04 activity간에 호출하기 & intent
PDF
03 activity.finish
PDF
02 activity.lifecycle
PDF
안드로이드 로그 파일로 남기기
PPTX
다양한 Device 대응_방법
Agile Spirit Base On The Book "Agile Samuari"
Uml intro 1
Uml intro 0
21 application and_network_status
20 handler and_async_task
18 안드로이드 리스트뷰_속도향상
19 나만의 view 만들기
17 adapter view & db
16 데이터 저장과 사용
15 content provider
14 broad castreceiver
11 tablet 대응 가이드
09 android keyboard & layout
08 font size
07 다양한 device_대응_방법
04 activity간에 호출하기 & intent
03 activity.finish
02 activity.lifecycle
안드로이드 로그 파일로 남기기
다양한 Device 대응_방법
Ad

13 service 좀더

  • 2. Activity는 여러 Instance가 생성되는 것으로 알고 있습니다. 그런데, Service도 요청 때 마다 여러 Service Instance가 생길까요?
  • 4. 특히나 IntentService는? IntentService는 Intent를 전달 받을 때 마다, 해당 Intent를 처리하도록 특화되어 있는 Service 중 하나입니다. 예를 들어서, 특정 데이터를 전송하고, 해당 데이터를 저장을 하는 작업과 같은 작업을 IntentService를 통해서 구현할 수 있습니다. IntentService에 대한 자세한 내용: http://developer.android.com/reference/android/app/IntentService.html 이 Service 경우 자체가 가지는 특수성에 따라서, Intent에 대해서 동시 다발적으로 처리가 수행이 되는지가 중요합니다. 이에 대해서 알아보도록 합니다.
  • 5. IntentService Overview IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests throughstartService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work. This "work queue processor" pattern is commonly used to offload tasks from an application's main thread. The IntentService class exists to simplify this pattern and take care of the mechanics. To use it, extend IntentService and implement onHandleIntent(Intent). IntentService will receive the Intents, launch a worker thread, and stop the service as appropriate. All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), but only one request will be processed at a time.
  • 6. 결론은! IntentService는 Intent를 가지고 여러 번 호출이 되더라도, 한 번에 하나씩 요청이 인입된 순서에 따라서 처리를 진행합니다. 처리할 Intent가 없으면, Service는 사라지고 신규 Intent가 도착하여 처리할 사항이 있으면 Service가 1개 신규 생성됩니다. 만약 Intent가 여러 개가 쭈욱 밀려 있으며, 처음 생성된 Intent가 모든 Intent를 순차적으로 처리를 하게 됩니다. 즉, IntentService는 하나의 Instance가 순차적으로 처리를 진행합니다.
  • 7. 테스트 진행 Service start가 호출될 때마다 Instance가 생성되어 호출이 되게 되면, Test time이 호출되는 내역이 번갈아 나타날 것이고 Instance 하나가 나타나면 순차적으로 나타날 것입니다.
  • 8. 테스트 결과 수행 1. 3회 연달아 서비스 호출 수행 2. 3회 처리 후 서비스 2회 연달아 호출 Thread ID. 처리할 작업이 없어지니 사라지고 새 처리 작업이 발생되니 새로 생성 확인 요청이 Multi가 아닌 Single로 순차적으로 처리됨을 확인
  • 9. 덧붙이자면~ Service에 대해서 동일한 테스트를 한 결과. Instance는 하나만 생성이 되고, Service가 제공이 됨이 확인되었습니다. 그렇지만, Service는 InstanceService와 별도로 Thread 하나가 메모리 상태에 꾸준히 떠 있는 데몬 형태와 같이 구동을 함을 확인 했습니다. 동일하게 3회/2회 연달아서 테스트. Thread ID 동일 확인