public class MyService extends Service {
private MyReceiver receiver;
private class MyReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
onDestroy();
}
}
public void onCreate() {
super.onCreate();
Toast.makeText(MyService.this, "服務已啟動", Toast.LENGTH_SHORT).show();
}
public int onStartCommand(Intent intent, int flags, int startId) {
receiver=new MyReceiver();
IntentFilter filter=new IntentFilter();
filter.addAction("net.s5c.Changelink.wifiOff");
registerReceiver(receiver, filter);
flags=START_STICKY;
return super.onStartCommand(intent, flags, startId);
}
public void onDestroy() {
Toast.makeText(this, "服務已關閉", Toast.LENGTH_LONG).show();//可以打印出這句,但看後台還是無法關閉服務!
super.onDestroy();
}
public IBinder onBind(Intent intent) {
return null;
}
}
收到廣播後能看到輸出的onDestroy()的內容,但看正在運行中服務還是繼續運行著,這是怎麼回事呢?
沒有任何作用看了半天也沒找到我需要的!