第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java android殺死服務(wù)

Java android殺死服務(wù)

哆啦的時光機 2022-06-15 15:07:08
我如何殺死這項服務(wù):private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {    if (!UsbService.SERVICE_CONNECTED) {        Intent startService = new Intent(this, service);        if (extras != null && !extras.isEmpty()) {            Set<String> keys = extras.keySet();            for (String key : keys) {                String extra = extras.getString(key);                startService.putExtra(key, extra);            }        }        startService(startService);    }    Intent bindingIntent = new Intent(this, service);    bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);}我嘗試這樣做:Intent intent = new Intent(MainMenu.this, UsbService.class);stopService(intent);但該服務(wù)一直有效。''這是我的服務(wù):public class UsbService extends Service {    public static final String ACTION_USB_READY = "pl.gps.connectivityservices.USB_READY";    public static final String ACTION_USB_ATTACHED = "android.hardware.usb.action.USB_DEVICE_ATTACHED";    public static final String ACTION_USB_DETACHED = "android.hardware.usb.action.USB_DEVICE_DETACHED";    public static final String ACTION_USB_NOT_SUPPORTED = "pl.gps.usbservice.USB_NOT_SUPPORTED";    public static final String ACTION_NO_USB = "pl..gps.usbservice.NO_USB";    public static final String ACTION_USB_PERMISSION_GRANTED = "pl.gps.usbservice.USB_PERMISSION_GRANTED";        }    };但是我的意圖服務(wù)竊取正在起作用。當(dāng)我銷毀創(chuàng)建此服務(wù)的活動時,我嘗試做 whis,但是當(dāng)此活動在日志中被銷毀時,我發(fā)現(xiàn)此意圖服務(wù)一直是鋼鐵加工
查看完整描述

1 回答

?
POPMUISE

TA貢獻1765條經(jīng)驗 獲得超5個贊

嘗試這個


使用 stopSelf();


一旦使用 stopSelf() 請求停止,系統(tǒng)會盡快銷毀服務(wù)。


有意圖地通過一些動作


Intent intent = new Intent(MainMenu.this, UsbService.class);

intent.setAction(Constants.ACTION.STOPTFOREGROUND_ACTION);

stopService(intent);

在您的服務(wù) onStartCommand()


 if(intent.getAction()==Constants.ACTION.STOPTFOREGROUND_ACTION){

     stopForeground(true);

     stopSelf();

   }

  public class Constants {

  public interface ACTION {

      String STOPFOREGROUND_ACTION = "com.package.packageName.action.stopforeground";

  }

  }


查看完整回答
反對 回復(fù) 2022-06-15
  • 1 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號