gkac 2015 apr. - android looper
TRANSCRIPT
![Page 1: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/1.jpg)
Android Looper차영호 @ganachoco
![Page 2: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/2.jpg)
발표자 소개
![Page 3: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/3.jpg)
Agenda● Java VS Android● Where is main?● Event Loop● Create and Handle Event with Message● Advanced Topic
![Page 4: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/4.jpg)
Android Looper● Event Loop for Android● 공기 같은 존재
○ 어디에나 있지만, 여간해선 사용할 일은 없다.○ 사용할 일은 없지만, 모르면 가끔씩 해결이 곤란할 때가 생긴다.
![Page 5: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/5.jpg)
Java vs Android
![Page 6: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/6.jpg)
Start Entry
public class Hello { public static void main(String[] s) { System.out.println("Hello, World"); }}
public class HelloActivity extends Activity { @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.activity_hello); }}
![Page 7: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/7.jpg)
Start EntryC:\ > java HelloHello, World
????
![Page 8: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/8.jpg)
간단한 호출경로 확인 방법(Log)
![Page 9: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/9.jpg)
간단한 호출경로 확인 방법(Log)
![Page 10: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/10.jpg)
main()package android.app;
public final class ActivityThread {
public static void main(String[] args) {
// blahblah
Looper.loop();
throw new RuntimeException("Main thread loop unexpectedly exited");
}
}
![Page 11: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/11.jpg)
Event Loopwhile (true) {
// do someting
}
![Page 12: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/12.jpg)
Event Loopwhile (true) {
msg = waitAndGetMessage();
handler = msg.getTarget();
handler.handleMessage(msg);
}
![Page 13: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/13.jpg)
간단한 호출경로 확인 방법(Log)
![Page 16: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/16.jpg)
ANR이 반겨줍니다.
![Page 17: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/17.jpg)
Events● Component Lifecycle Event
○ Activity○ Service
● Intent Handler○ BroadcastReceiver.onReceive
● View layout & draw● Input Event
![Page 18: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/18.jpg)
Event Loop● android.os.Message● android.os.Handler● android.os.Looper
○ android.os.HandlerThread
![Page 19: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/19.jpg)
Message@Overridepublic void onClick(View v) { setText("Text 1");}
private static final int MSG_HANDLE_CHANGE_TEXT = 1;
public void setText(String text) { // Message msg = new Message(); // bad usage Message msg = mHandler.obtainMessage(MSG_HANDLE_CHANGE_TEXT, text); mHandler.sendMessage(msg);}
![Page 20: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/20.jpg)
Handlerprivate mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_HANDLE_TEXT_CHANGED: mTextView.setText((String)(msg.obj)); break; default: break; } }}
![Page 21: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/21.jpg)
Call FlowLooper.loop onClick setText mHandler.sendMessage
... mHandler.handleMessage mTextView.setText
시간
![Page 22: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/22.jpg)
직구를 배웠습니다
![Page 23: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/23.jpg)
변화구도 배워봅시다
Image Source: https://mirror.enha.kr/wiki/야구의 구종
![Page 24: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/24.jpg)
Message Queue
Image Source: MSDN
sendMessageAtFrontOfQueue()
![Page 25: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/25.jpg)
Message Queue
Image Source: MSDNremoveMessages()
![Page 26: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/26.jpg)
Message Queue
Image Source: MSDN
sendMessageDelayed()
sendMessageAtTime()
![Page 27: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/27.jpg)
Requirement
● 안드로이드앱이 시작하고나서 1분 후에 팝업을 띄워주세요.
![Page 28: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/28.jpg)
Solution
![Page 29: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/29.jpg)
Advanced Topic● Wakelock● AlarmManager
![Page 30: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/30.jpg)
Wakelock● View.setKeepScreenOn()● WakeLock
○ FULL_WAKE_LOCK○ SCREEN_BRIGHT_WAKE_LOCK○ SCREEN_DIM_WAKE_LOCK○ PARTIAL_WAKE_LOCK
![Page 31: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/31.jpg)
AlarmManager
● ELAPSED_REALTIME● ELAPSED_REALTIME_WAKEUP● RTC● RTC_WAKEUP
![Page 32: GKAC 2015 Apr. - Android Looper](https://reader035.vdocuments.pub/reader035/viewer/2022062515/55c0f1e0bb61eb99428b4587/html5/thumbnails/32.jpg)
Q&A