0
如何正確停止Broadcast receiver中的服務?我正在使用短信接收廣播接收器。在BroadcastReceiver中同時停止BroadcastReceiver和服務
我使用
context.stopService(new Intent(this, CallService.class));
其中 「CallService」 是我的服務,但我收到
The constructor Intent(SMSReceiver, Class<CallService>) is undefined
和快速修復是remove the arguments to match 'Intent()'
我在這裏做得不對?
要停止廣播接收器,所有我需要做的就是 context.unregisterReceiver(SMSReceiver.this);
這一切?我必須做Destroy或什麼? 謝謝。
哇!這不會產生任何錯誤,但我很快就會在編譯的應用程序中進行操作。但是你介意解釋一下,爲什麼我們這次使用'context',而不是'this'? – MrYanDao
意圖需要一個上下文對象作爲第一個參數,但BroadcastReciever(與活動和服務不同)不會擴展上下文對象。所以你不能使用這個 – nandeesh