我有一个线程类:
private class Mythread extends Thread{
boolean mfinish = false;
private void finish(){
mfinish = true;
interrupt();
}
while(!mfinish){ do my work}
}
我使用SparseArray<Mythread> mThreadArray
来保存线程。
我在我的服务A:
中注册了BroadcastReceiver
private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver(){
public void onReceive(Context context, Intent intent) {
if(intent.getAction().euqals(STOP_THREAD)){
uid = bundle.getInt("uid");
pid = bundle.getInt("pid");
tid = bundle.getInt("tid");
if(mThreadArray.get(tid)==null){
Mythread samplThread = new Mythread(pid, tid);
mThreadArray.put(tid,sampleMainThread);
sampleThread.start();
}
}
if(intent.getAction().equals(STOP_THREAD)){
uid = bundle.getInt("uid");
pid = bundle.getInt("pid");
tid = bundle.getInt("tid");
if(mThreadArray.get(tid)!=null){
mThreadArray.get(tid).finish();
mThreadArray.remove(tid);
}
}
}
}
在另一个应用程序B中,创建或结束有线程时sentBroadcast()
。
但是,在我的服务A中,我发现当&#34;停止&#34;时,不能停止创建的线程。意图来了。
有没有人知道原因?