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>
更多精彩
赞助商链接