![](/img/trans.png)
[英]Why does my Android service get restarted when the process is killed, even though I used START_NOT_STICKY?
[英]When I kill a process in Android a Service is not restarted
我知道當我按下 logcat 中的紅色方形按鈕時我可以殺死一個進程(選擇了相應的設備和進程)。
但是,當我這樣做時,服務並沒有像我期望的那樣重新啟動。 它調用 onCreate 和 onDestroy 並且它不調用 onStartCommand 盡管事實上 onStartCommand 返回 START_STICKY 。
我向您展示了我的代碼,如果您知道問題可能出在哪里,請告訴我
你需要stop service
:
Intent myService = new Intent(MainActivity.this, BackgroundSoundService.class);
stopService(myService);
您是否在清單文件中聲明了服務
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.