我创建了线程以从网站获取json数据,然后分析数据并显示通知。
但是,当我关闭该应用程序时,再次打开该应用程序后该线程仍在工作,该应用程序崩溃了。有什么办法吗?而且我在onDestroy生命周期中使用了interrupt()
@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"Closed",Toast.LENGTH_SHORT).show();
//Configuration configuration = new Configuration();
//condition = 1;
test.interrupt();
//test.destroy();
}
在您的run()方法中,您需要定期检查 ThreadName.interrupted()
这里有一个很好的教程:http : //docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句