怎样彻底杀死一个Android的线程? [英] How do I kill an Android thread completely?
本文介绍了怎样彻底杀死一个Android的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有有后台运行它自己的线程的服务。我想杀死服务,包括线程。
I have a service that has its own thread running on background. I'd like to kill that service including the thread.
我创造了这样的线程并运行它。
I created the thread like this and run it.
public class DaemonService extends Service {
private DaemonThread thread;
class DaemonThread extends Thread {
public void run()
{
runDaemon(mArgv.toArray(), mConfig);
}
}
public void onStart(Intent intent, int startId) {
thread = new DaemonThread();
thread.start();
}
}
我如何杀死服务线程呢?我不必担心数据的安全。
How do I kill the service and the thread as well? I don't have to worry about data safety..
推荐答案
要杀死线程,我认为你可以这样做:
to kill the thread , i think you can do like this :
myService.getThread().interrupt();
注意:的方法使用Thread.stop()
是pcated德$ P $
NOTE : the method Thread.stop()
is deprecated
编辑::试试这个
public void stopThread(){
if(myService.getThread()!=null){
myService.getThread().interrupt();
myService.setThread(null);
}
}
这篇关于怎样彻底杀死一个Android的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文