I use the application interconnected with the service, in the onDestroy method of the application the launch of the service with notification is set.
@Override public void onDestroy() { if (mediaPlayer.isPlaying()) { Intent i = new Intent(this, MyService.class); i.setAction(Constants.SERVICE.SERVICE_IN_BACKGROUND); startService(i); } super.onDestroy(); } That is, if the user minimizes the application, the service starts with a notification, if it expands again, then the notification is closed.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (notificationManager != null) { notificationManager.cancel(NOTIFICATION_ID); } } Faced a problem when an application is minimized, if you clear it from background applications, the notification service lives on, but since it was associated with the application, its functions in the notification do not work. Is there any method that works when an application is completely destroyed? So that I destroy the service with the notification. For example, if I minimized the application and cleared it from the background processes so that the service was also destroyed?