runing a background service after android marshmallow is a headache.
every background operation is suspended by Doze and StandBy Modes.
and even if you use job dispatcher or WorkManger the Minimum interval to run operation is 15 mins even though you set the minimun interval less than 15 mins.
So you need to start a foreground service with sticky notification to do you work. you can take a look on this article to Start working with foreground services.
don't forget to put this premission into manifest file if your app will run on androi Pie
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
and you can rerun you service on phone restart by using a broadcast receiver
which listen to this action
<action android:name="android.intent.action.BOOT_COMPLETED" />
and also you can stop it by listening to this action
<action android:name="android.intent.action.ACTION_SHUTDOWN" />