Как сделать незакрываемое приложение андроид
как сделать так, чтобы приложение не закрывалось, а продолжало работать в фоновом режиме? Даже после того как пользователь его закрыл из меню. Есть такие приложения, которые закрываешь, а уведомления и их работа в фоне остаётся. Я сделал постоянное уведомление для этого, но всё равно приложение закрывается.
private NotificationManager notificationManager;
private static final int NOTIFY_ID = 1;
private static final String CHANNEL_ID = "CHANNEL_ID";
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notificationBuilder.setOngoing(true);
notificationBuilder.setAutoCancel(false);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher_foreground);
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setContentTitle("Заголовок");
notificationBuilder.setContentText("Какой-то текст");
notificationBuilder.setPriority(PRIORITY_HIGH);
createNotificationMangaer(notificationManager);
notificationManager.notify(NOTIFY_ID, notificationBuilder.build());