WEB开发网
开发学院手机开发Android 开发 android平台中的Handler和HandlerThread使用方法 阅读

android平台中的Handler和HandlerThread使用方法

 2012-12-25 19:10:58 来源:WEB开发网   
核心提示:HandlerThread使用方法:<span style="color:#666666; font-style:italic">//把上面创建Handler的代码</span>Handler handler <span style="color:#33993

HandlerThread使用方法:

<span style="color:#666666; font-style:italic">//把上面创建Handler的代码</span>
Handler handler <span style="color:#339933">=</span> <span style="color:#000000; font-weight:bold">new</span> Handler<span style="color:#0990">(</span><span style="color:#0990">)</span> <span style="color:#0990">{</span>
...
<span style="color:#0990">}</span>
 
<span style="color:#666666; font-style:italic">//改为:</span>
HandlerThread thread <span style="color:#339933">=</span> <span style="color:#000000; font-weight:bold">new</span> HandlerThread<span style="color:#0990">(</span><span style="color:#00ff">"athread"</span><span style="color:#0990">)</span><span style="color:#339933">;</span>
thread.<span style="color:#06633">start</span><span style="color:#0990">(</span><span style="color:#0990">)</span><span style="color:#339933">;</span> <span style="color:#666666; font-style:italic">//要把线程启动</span>
 
Handler handler <span style="color:#339933">=</span> <span style="color:#000000; font-weight:bold">new</span> Handler<span style="color:#0990">(</span>thread.<span style="color:#06633">getLooper</span><span style="color:#0990">(</span><span style="color:#0990">)</span><span style="color:#0990">)</span> <span style="color:#0990">{</span>
...
<span style="color:#0990">}</span>

上一页  1 2 

Tags:android 平台 Handler

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接