我正在从我的安卓应用程序中的意图服务启动前台服务,服务从通知开始。这就是我开始服务的方式:
Intent intent = new Intent(this, NavigationforegroundService.class);
startService(intent);
我正在 NotificationListenerService 中侦听特定应用的通知,当该通知被删除时,我正在停止前台服务,但前台服务仍在运行。这就是我停止前台服务的方式:
stopForeground(false);
stopService(new Intent(RemoteViewNotificationReaderService.this, NavigationforegroundService.class));
我找不到任何线索为什么服务没有停止,因为文档还建议使用 stopService(( 或 stopSelf(( 方法。任何人都可以告诉我我做错了什么,或者停止其他服务的正确方法是什么。
谢谢。
请编写以下代码以停止地面服务。
从您的服务呼叫stopForeground(true)
,然后stopSelf()
以停止您的地面服务。