在runnable分别加入ondestroy()和stopself();
在断点中下面的代码都执行了,
但是再一次startservice(线程)的时候前者提示Thread is started异常,
后者则正常
@Override
public void onDestroy(){
super.onDestroy();
ListData.interrupt();
}
在runnable分别加入ondestroy()和stopself();
在断点中下面的代码都执行了,
但是再一次startservice(线程)的时候前者提示Thread is started异常,
后者则正常
@Override
public void onDestroy(){
super.onDestroy();
ListData.interrupt();
}
interrupt()并不会真正结束掉线程。看下Java的源码,这个方法只是Just to set the interrupt flag,设置了一个flag,并不是真正的中断线程。正确做法是需要在runnable方法中判断线程状态。使用isInterupt()方法