ForegroundService no Android Oreo é morto

Estou tentando criar um serviço que solicita a localização do dispositivo a cada minuto. Eu preciso que isso funcione em segundo plano, mesmo quando o aplicativo estiver fechado. Até agora, consegui fazê-lo funcionar em dispositivos com um sistema operacional Android pré-Oreo, mas agora estou testando o serviço no dispositivo Android Oreo e não está funcionando quando fecho ou coloco o aplicativo em segundo plano. Na minha pesquisa, descobri que, para dispositivos Oreo, um Serviço em Primeiro Plano com uma notificação em andamento deve ser usado para conseguir isso. Para começar, implementei um Serviço em Primeiro Plano simples como o abaixo. é removido

public class MyForegroundService extends Service {

    private static String TAG = MyForegroundService.class.getSimpleName();

    private static final String CHANNEL_ID = "channel_01";
    private static final int NOTIFICATION_ID = 12345678;

    private NotificationManager mNotificationManager;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    public MyForegroundService() {
        super();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate");

        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        // Android O requires a Notification Channel.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = getString(R.string.app_name);

            // Create the channel for the notification
            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);

            // Set the Notification Channel for the Notification Manager.
            mNotificationManager.createNotificationChannel(mChannel);
        }

        startForeground(NOTIFICATION_ID, getNotification());
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "onStartCommand");

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy");

        stopForeground(true);
    }

    private Notification getNotification() {

        // Get the application name from the Settings
        String appName = PrefApp.getSettings(getApplicationContext()).getAppConfigs().getAppName();
        String applicationKey = PrefApp.getSettings(getApplicationContext()).getAppConfigs().getAppKey();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setContentTitle(appName)
                .setContentText("Services are running")
                .setOngoing(true)
                .setPriority(Notification.PRIORITY_HIGH)
                .setSmallIcon(R.mipmap.ic_notification)
                .setWhen(System.currentTimeMillis());

        // Set the Channel ID for Android O.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            builder.setChannelId(CHANNEL_ID); // Channel ID
        }

        return builder.build();
    }
}

Estou iniciando e parando o serviço acima usando as funções abaix

public void startMyForegroundService() {
    Log.d(TAG, "Start Foreground Service");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        startForegroundService(new Intent(getApplicationContext(), MyForegroundService.class));
    } else {
        startService(new Intent(getApplicationContext(), MyForegroundService.class));
    }
}

public void stopMyForegroundService() {
    Log.d(TAG, "Stop Foreground Service");
    stopService(new Intent(getApplicationContext(), MyForegroundService.class));
}

Estou testando o serviço acima e, por algum motivo, o serviço é interrompido após cerca de 30 minutos após o início. Alguém pode me dizer se estou fazendo algo errado ou possivelmente me orientar para uma solução que possa funcionar para mim?

Nota: eu segui issotutoria e testou sua aplicação também e ainda não está funcionando. O serviço está sendo morto depois de algum tempo.

Basicamente, meu objetivo é implementar um serviço que possa ser executado em segundo plano (mesmo quando o aplicativo estiver fechado) e obter atualizações de localização a cada minut

questionAnswers(1)

yourAnswerToTheQuestion