일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- FLUTTER
- NDK
- RxJava
- UWP
- C++
- Kotlin
- 코틀린
- 안드로이드 구글맵
- mfc
- Django REST Android
- Django REST framework
- 프로그래머스
- 알고리즘
- RxAndroid
- Android P
- android push
- livedata
- Android
- Python
- kodility
- 안드로이드
- Java
- Flutter TextField
- flutter firestore
- C/C++
- Rxjava2
- android architecture component
- dart
- C
- Django REST
- Today
- Total
개발하는 두더지
[Android/안드로이드/자바] Thread, Runnable, Handler 에 대해 알아보기 본문
1. Thread 개념 잡기
2. Runnable 개념 잡기
3. Handler 개념 잡기
4. 각각의 사용 방법
5. 예제
Thread
A Thread
is a concurrent unit of execution. It has its own call stack for methods being invoked, their arguments and local variables. Each application has at least one thread running when it is started, the main thread, in the main ThreadGroup
. The runtime keeps its own threads in the system thread group.
There are two ways to execute code in a new thread. You can either subclass Thread
and overriding its run()
method, or construct a new Thread
and pass aRunnable
to the constructor. In either case, the start()
method must be called to actually execute the new Thread
.
Runnable
Thread
Handler
A Handler allows you to send and process Message
and Runnable objects associated with a thread's MessageQueue
. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.
There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.
// 스레드에서 UI 변경 작업을 하고 싶다면 핸들러를 쓰면 된다.
'Java,Android' 카테고리의 다른 글
[Android/안드로이드] 다음 쇼핑 api 를 이용한 상품 검색 프로그램 ( 다음 API, JSON, ListView 활용 ) (0) | 2016.07.22 |
---|---|
[Android/안드로이드] Service와 BroadcastReceiver로 스크린 화면 감지하기 (7) | 2016.07.22 |
[Android/안드로이드] 안드로이드 파일 탐색기 구현 (2) | 2016.07.22 |
[Android/안드로이드] InputStream, OutputStream을 활용한 동영상 다운로드 및 재생 (0) | 2016.07.22 |
[Android/안드로이드] sdcard 절대 경로 찾기 - JellyBean(젤리빈) 이상부터 내장 메모리의 변동, galaxy S3, S4 sdcard 문제 (0) | 2016.07.22 |