android线程启动问题
我正在声明一个线程来执行某些工作,
Thread download= new Thread("download"){
public void run(){
Looper.prepare();
downloadThreadHandler = new Handler();
Looper.loop();
}
};
download.start();
并且我正在向线程发布可运行对象以在线程内执行任务。
downloadThreadHandler.post(new Runnable() {});
当这两个片段立即出现时,就会发生异常。 如果启动线程和发布 Runnables 之间存在一些延迟,那么它可以正常工作。 另外,我找不到问题,因为调试过程会增加延迟,并且在调试时工作正常
I am stating a thread to do certain jobs,
Thread download= new Thread("download"){
public void run(){
Looper.prepare();
downloadThreadHandler = new Handler();
Looper.loop();
}
};
download.start();
And I am giving posting Runnables to thread to do tasks inside thread.
downloadThreadHandler.post(new Runnable() {});
When these two snippets are immediate then exception occurs.
If there is some delay between starting thread and posting Runnables, then it works fine.
Also I could not find problem because debugging process adds that delay and it works fine while debugging
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布到线程可能发生在循环完全启动之前。延迟让循环开始。
Post to thread probably occurs before loop fully started. Delay lets loop start.