SlideShare a Scribd company logo
1 of 17
AndroidAnnotations
Threading
작성자 – 김태희 최종 수정일: 151202
Threading
Enhanced components는
안드로이드의 기본 컴포넌트들을
쉽고 빠르게 사용할 수 있도록 해 줍니다.
Threading
구성
@Background
@UiThread
@SupposeBackground
@SupposeUiThread
Threading
구성
@Background
@UiThread
@SupposeBackground
@SupposeUiThread
본 강에서는 이 중 주요
annotation들을 활용한 예제
어플리케이션을 통해 사용법을
익혀보도록 합니다.
예제 소스 코드는 아래에서 확인하실 수 있습니다.
https://github.com/JuranoSaurus/ThreadingSample
@Background
0.5초마다 숫자를 1씩 증가시키며
로그를 찍는 예제입니다.
Activity 생성시 Background Task를
실행하며 버튼을 통해 Interrupt를
발생시켜 Background Task를 멈출
수 있습니다.
다음 장에서는 AA를
사용하지 않고 Java
Thread를 사용했을 때의
예시를 보겠습니다.
TASK_ID를 Key로 가지는 Map을 활용하여
ThreadPool을 만들고, 버튼을 누르면 해당
TASK_ID를 가진 Thread를 찾아 interrupt()합니다.
TASK_ID를 Key로 가지는 Map을 활용하여
ThreadPool을 만들고, 버튼을 누르면 해당
TASK_ID를 가진 Thread를 찾아 interrupt()합니다.
btnStopTask()가 호출되었을 때의 모습입니다.
InterruptedException을 통해 Thread를 종료하였습니다.
@Background
그렇다면 @Background annotation을
사용했을 때는 어떻게 될까요?
@Background로 지정된
메소드를 호출하는 것만으로
Thread를 시작할 수
있습니다.
이는 AA 내부적으로 구현된
BackgroundExecutor를
활용한 것으로,
정지 등 일련의 조작은
BackgroundExecutor를 통해
수행할 수 있습니다.
id를 통해 쉽게 조작할 수
있다는 것이 특장점으로
꼽힙니다.
내부의 thread pool은
ArrayList로 구현되어 있습니다.
thread는 Runnable 인터페이스를 구현한
것임을 확인할 수 있습니다.
@UiThread
지금까지는 @Background를 활용하여
background task를 수행하는 법에 대해 알아보았습니다.
그럼 View에 영향을 줄 수 있는
RunOnUiThread()는 어떻게 사용할까요?
기본 안드로이드는
RunOnUiThread()를 통해
View를 컨트롤 하는 것이
가능합니다.
이에 반해 @UiThread를
사용하면 다음과 같이 메소드
형태로 작성할 수 있습니다.
annotation 이름이
@UiThread로 별도의
스레드가 아닌가? 라고
혼동하실 수 있지만
RunOnUiThread()에 대한
wrapper라고 생각하시는게
옳습니다.
@Background때와 다르게
TextView의 값을 변경 가능한
것을 확인할 수 있습니다.
^_^
@More
즐거우셨나요? ^_^
다음 편에는 Resource Injection에 대한
annotation들을 알아보도록 하겠습니다.
Thank you

More Related Content

Similar to Jurano강의 lec6 android_annotations_threading

『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법
『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법
『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법복연 이
 
191221 unreal engine 4 editor 확장하기
191221 unreal engine 4 editor 확장하기191221 unreal engine 4 editor 확장하기
191221 unreal engine 4 editor 확장하기KWANGIL KIM
 
Create document automatically (1)
Create document automatically (1)Create document automatically (1)
Create document automatically (1)SangJune Ahn
 
HolubOnPatterns/chapter2_1
HolubOnPatterns/chapter2_1HolubOnPatterns/chapter2_1
HolubOnPatterns/chapter2_1정환 임
 
Holub on-patterns-2-1
Holub on-patterns-2-1Holub on-patterns-2-1
Holub on-patterns-2-1정환 임
 
LINC3.0 캡스톤디자인 경진대회_로운팀.pptx
LINC3.0 캡스톤디자인 경진대회_로운팀.pptxLINC3.0 캡스톤디자인 경진대회_로운팀.pptx
LINC3.0 캡스톤디자인 경진대회_로운팀.pptxssuser20022f
 
Implementing_AOP_in_Spring_SYS4U
Implementing_AOP_in_Spring_SYS4UImplementing_AOP_in_Spring_SYS4U
Implementing_AOP_in_Spring_SYS4Usys4u
 
리액트 18 공유.pptx
리액트 18 공유.pptx리액트 18 공유.pptx
리액트 18 공유.pptxcksal4785911
 
3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약Tae wook kang
 
회사에서 기술서적을 읽는다는것
회사에서 기술서적을 읽는다는것회사에서 기술서적을 읽는다는것
회사에서 기술서적을 읽는다는것성환 조
 
Du room system_portfolio
Du room system_portfolioDu room system_portfolio
Du room system_portfolio진영 최
 

Similar to Jurano강의 lec6 android_annotations_threading (11)

『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법
『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법
『이펙티브 디버깅』 - 디버깅 지옥에서 탈출하는 66가지 전략과 기법
 
191221 unreal engine 4 editor 확장하기
191221 unreal engine 4 editor 확장하기191221 unreal engine 4 editor 확장하기
191221 unreal engine 4 editor 확장하기
 
Create document automatically (1)
Create document automatically (1)Create document automatically (1)
Create document automatically (1)
 
HolubOnPatterns/chapter2_1
HolubOnPatterns/chapter2_1HolubOnPatterns/chapter2_1
HolubOnPatterns/chapter2_1
 
Holub on-patterns-2-1
Holub on-patterns-2-1Holub on-patterns-2-1
Holub on-patterns-2-1
 
LINC3.0 캡스톤디자인 경진대회_로운팀.pptx
LINC3.0 캡스톤디자인 경진대회_로운팀.pptxLINC3.0 캡스톤디자인 경진대회_로운팀.pptx
LINC3.0 캡스톤디자인 경진대회_로운팀.pptx
 
Implementing_AOP_in_Spring_SYS4U
Implementing_AOP_in_Spring_SYS4UImplementing_AOP_in_Spring_SYS4U
Implementing_AOP_in_Spring_SYS4U
 
리액트 18 공유.pptx
리액트 18 공유.pptx리액트 18 공유.pptx
리액트 18 공유.pptx
 
3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약
 
회사에서 기술서적을 읽는다는것
회사에서 기술서적을 읽는다는것회사에서 기술서적을 읽는다는것
회사에서 기술서적을 읽는다는것
 
Du room system_portfolio
Du room system_portfolioDu room system_portfolio
Du room system_portfolio
 

More from Ju-ri Seo

Jurano강의 lec7 android_annotations_resource_injection_and_rest_api
Jurano강의 lec7 android_annotations_resource_injection_and_rest_apiJurano강의 lec7 android_annotations_resource_injection_and_rest_api
Jurano강의 lec7 android_annotations_resource_injection_and_rest_apiJu-ri Seo
 
Jurano강의 lec5 android_annotations_event_binding
Jurano강의 lec5 android_annotations_event_bindingJurano강의 lec5 android_annotations_event_binding
Jurano강의 lec5 android_annotations_event_bindingJu-ri Seo
 
Jurano강의 lec4 android_annotations_application
Jurano강의 lec4 android_annotations_applicationJurano강의 lec4 android_annotations_application
Jurano강의 lec4 android_annotations_applicationJu-ri Seo
 
Jurano강의 lec2. sample application 둘러보기
Jurano강의 lec2. sample application 둘러보기Jurano강의 lec2. sample application 둘러보기
Jurano강의 lec2. sample application 둘러보기Ju-ri Seo
 
Jurano강의 lec1. AndroidAnnotations 시작하기
Jurano강의 lec1. AndroidAnnotations 시작하기Jurano강의 lec1. AndroidAnnotations 시작하기
Jurano강의 lec1. AndroidAnnotations 시작하기Ju-ri Seo
 
150708 알고리즘 문제풀이 이것은 알자
150708 알고리즘 문제풀이 이것은 알자150708 알고리즘 문제풀이 이것은 알자
150708 알고리즘 문제풀이 이것은 알자Ju-ri Seo
 

More from Ju-ri Seo (6)

Jurano강의 lec7 android_annotations_resource_injection_and_rest_api
Jurano강의 lec7 android_annotations_resource_injection_and_rest_apiJurano강의 lec7 android_annotations_resource_injection_and_rest_api
Jurano강의 lec7 android_annotations_resource_injection_and_rest_api
 
Jurano강의 lec5 android_annotations_event_binding
Jurano강의 lec5 android_annotations_event_bindingJurano강의 lec5 android_annotations_event_binding
Jurano강의 lec5 android_annotations_event_binding
 
Jurano강의 lec4 android_annotations_application
Jurano강의 lec4 android_annotations_applicationJurano강의 lec4 android_annotations_application
Jurano강의 lec4 android_annotations_application
 
Jurano강의 lec2. sample application 둘러보기
Jurano강의 lec2. sample application 둘러보기Jurano강의 lec2. sample application 둘러보기
Jurano강의 lec2. sample application 둘러보기
 
Jurano강의 lec1. AndroidAnnotations 시작하기
Jurano강의 lec1. AndroidAnnotations 시작하기Jurano강의 lec1. AndroidAnnotations 시작하기
Jurano강의 lec1. AndroidAnnotations 시작하기
 
150708 알고리즘 문제풀이 이것은 알자
150708 알고리즘 문제풀이 이것은 알자150708 알고리즘 문제풀이 이것은 알자
150708 알고리즘 문제풀이 이것은 알자
 

Jurano강의 lec6 android_annotations_threading