Toast 和Timer与 Can't create handler inside thread that has not called Looper.prepare()问题

来源:互联网 发布:淘宝二手官方下载 编辑:程序博客网 时间:2024/06/05 19:29

参考资料:http://jeff-pluto-1874.iteye.com/blog/869710,

http://www.cnblogs.com/Greenwood/archive/2011/02/27/1966472.html。

关键代码


Timer timer=new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {Looper.prepare();// TODO Auto-generated method stubToast.makeText(getApplicationContext(), "您的账户已经刷新.", Toast.LENGTH_SHORT).show();Looper.loop(); //codes after this will not be excuted.}}, 5000);

 Looper.prepare()和 Looper.loop()的位置很重要。Looper.loop()后的代码是不会被执行的来。


原创粉丝点击