handler自定义使用

<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">public</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">class</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyHandlerActivity </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">extends</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> Activity {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 2</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    Button button;
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 3</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    MyHandler myHandler;
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 4</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 5</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">protected</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">void</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> onCreate(Bundle savedInstanceState) {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 6</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">super</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">.onCreate(savedInstanceState);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 7</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        setContentView(R.layout.handlertest);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 8</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);"> 9</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        button </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> (Button) findViewById(R.id.button);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">10</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        myHandler </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">new</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyHandler();
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">11</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 当创建一个新的Handler实例时, 它会绑定到当前线程和消息的队列中,开始分发数据
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">12</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> Handler有两个作用, (1) : 定时执行Message和Runnalbe 对象
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">13</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> (2): 让一个动作,在不同的线程中执行.
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">14</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">15</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 它安排消息,用以下方法
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">16</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> post(Runnable)
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">17</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> postAtTime(Runnable,long)
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">18</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> postDelayed(Runnable,long)
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">19</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> sendEmptyMessage(int)
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">20</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> sendMessage(Message);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">21</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> sendMessageAtTime(Message,long)
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">22</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> sendMessageDelayed(Message,long)
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">23</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">      
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">24</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 以上方法以 post开头的允许你处理Runnable对象
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">25</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">sendMessage()允许你处理Message对象(Message里可以包含数据,)</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">26</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">27</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        MyThread m </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">new</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyThread();
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">28</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">new</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> Thread(m).start();
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">29</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">30</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">31</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">/**</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">32</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">    * 接受消息,处理消息 ,此Handler会与当前主线程一块运行
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">33</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">    * </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">*/</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">34</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">35</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">class</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyHandler </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">extends</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> Handler {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">36</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">public</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyHandler() {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">37</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">38</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">39</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">public</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyHandler(Looper L) {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">40</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">super</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">(L);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">41</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">42</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">43</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 子类必须重写此方法,接受数据</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">44</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        @Override
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">45</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">public</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">void</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> handleMessage(Message msg) {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">46</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> TODO Auto-generated method stub</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">47</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            Log.d(</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">MyHandler</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">, </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">handleMessage......</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">48</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">super</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">.handleMessage(msg);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">49</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 此处可以更新UI</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">50</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            Bundle b </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> msg.getData();
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">51</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            String color </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> b.getString(</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">color</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">52</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            MyHandlerActivity.</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">this</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">.button.append(color);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">53</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">54</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">55</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">56</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">57</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">class</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> MyThread </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">implements</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> Runnable {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">58</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">public</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">void</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> run() {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">59</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">60</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">try</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">61</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">                Thread.sleep(</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">10000</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">62</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            } </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">catch</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> (InterruptedException e) {
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">63</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">                </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> TODO Auto-generated catch block</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">64</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">                e.printStackTrace();
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">65</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">66</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">67</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            Log.d(</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">thread.......</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">, </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">mThread........</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">68</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            Message msg </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">new</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> Message();
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">69</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            Bundle b </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">=</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">new</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;"> Bundle();</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 存放数据</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">70</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            b.putString(</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">color</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">, </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">我的</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">"</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">71</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            msg.setData(b);
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">72</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">73</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">            MyHandlerActivity.</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 0, 255);">this</span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">.myHandler.sendMessage(msg); </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">//</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"> 向Handler发送消息,更新UI</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">74</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 0);"></span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">75</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">        }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">76</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span><span style="font-family: Arial; font-size: 14px; line-height: 26px;">    }
</span><span style="font-family: Arial; font-size: 14px; line-height: 26px; color: rgb(0, 128, 128);">77</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值