Short answer is - you can not.
Years ago you could start real background services. I still have Kitkat device that runs one of those, without any problems, for years.
For a while now, you have to put a notification and run "foreground" service.
(Newer devices can dismiss this notification, then your service gets stopped. Older devices at least had the protection from closing.)
I will not go into details, but even the OS can kill non-system application, for whatever reason. (This happens when you let every manufacturer write his own interpretation of "good OS")
I advise you to consider the background and the foreground as separate processes. And arrange communication between them accordingly.
(Broadcast, notifications, etc.)
The truth is, that with every Android release this situation gets worse. And this requires continuous engineering effort to keep this organization working. So if you find a way to avoid it, before you have made it once, it will be even better.