1.Androidä¹Looper使ç¨
Androidä¹Looper使ç¨
轮轮询spark stream源码Looperæ¯Androidä¸çä¸ä¸ªç±»ï¼ç¨äºä¸ºçº¿ç¨æä¾æ¶æ¯å¾ªç¯ãå¨Androidä¸ï¼ä¸»çº¿ç¨å·²ç»é»è®¤å¼å¯äºä¸ä¸ªLooperï¼å æ¤å¯ä»¥ç´æ¥ä½¿ç¨Handleræ¥åéæ¶æ¯ãä½æ¯å¯¹äºå ¶ä»çº¿ç¨ï¼å¦æéè¦ä½¿ç¨Handleræ¥åéæ¶æ¯ï¼å°±éè¦å å建ä¸ä¸ªLooperã
轮轮询spark stream源码以ä¸æ¯ä½¿ç¨Looperçæ¥éª¤ï¼
轮轮询spark stream源码1. å¨å线ç¨ä¸å建ä¸ä¸ªLooper对象ï¼å¹¶è°ç¨Looperçprepare()æ¹æ³åLooperçloop()æ¹æ³ï¼è¿æ ·å°±å¯ä»¥ä¸ºè¯¥çº¿ç¨å建ä¸ä¸ªæ¶æ¯å¾ªç¯ã
轮轮询spark stream源码```java
轮轮询spark stream源码public class MyThread extends Thread {
轮轮询spark stream源码public Handler mHandler;
轮轮询spark stream源码public void run() {
轮轮询spark stream源码// å建Looper对象
轮轮询spark stream源码Looper.prepare();
轮轮询spark stream源码// å建Handler对象
轮轮询spark stream源码mHandler = new Handler() {
轮轮询spark stream源码public void handleMessage(Message msg) {
轮轮询spark stream源码// å¤çæ¶æ¯
轮轮询spark stream源码}
轮轮询spark stream源码};
轮轮询spark stream源码// è¿å ¥æ¶æ¯å¾ªç¯
轮轮询spark stream源码Looper.loop();
轮轮询spark stream源码}
轮轮询spark stream源码}
轮轮询spark stream源码```
轮轮询spark stream源码2. å¨ä¸»çº¿ç¨æå ¶ä»çº¿ç¨ä¸ï¼å¯ä»¥éè¿Handlerå该线ç¨åéæ¶æ¯ã
轮轮询spark stream源码```java
轮轮询spark stream源码MyThread thread = new MyThread();
轮轮询spark stream源码thread.start();
轮轮询spark stream源码// åå线ç¨åéæ¶æ¯
轮轮询spark stream源码thread.mHandler.sendEmptyMessage(1);
轮轮询spark stream源码```
轮轮询spark stream源码å¨ä½¿ç¨å®Looperä¹åï¼éè¦è°ç¨Looperçquit()æ¹æ³æ¥éåºæ¶æ¯å¾ªç¯ã
轮轮询spark stream源码```java
轮轮询spark stream源码Looper.myLooper().quit();
轮轮询spark stream源码```
轮轮询spark stream源码éè¦æ³¨æçæ¯ï¼Looperæ¯ä¸ä¸ªè½®è¯¢æ¶æ¯éåçæ é循ç¯ï¼å¦æ没ææ¶æ¯éè¦å¤çï¼ä¼ä¸ç´é»å¡å¨loop()æ¹æ³å¤ï¼å æ¤éè¦è°¨æ 使ç¨ï¼é¿å åºç°æ»å¾ªç¯æå åæ³æ¼çé®é¢ã
轮轮询spark stream源码