Maintainer of Red Moon, a screen filter app, here. I've struggled with similar problems as others describe for a long time.
As far as I know, the only truly 100% reliable way to never be killed is to run as an accessibility service. I haven't implemented this in Red Moon but will likely add it as an option. I believe it has a large impact on bettery life.
You can also set alarms using AlarmManager to restart the service if it has been killed, and optionally wake up the device. This is what DNS66 does.
This might have changed since, but in 2017 LastPass had to work with Google to update how they run their app. Google introduced "a new policy restricting the use of Android Accessibility Services" [1]
I'd look into that before starting that implementation.
As far as I know, the only truly 100% reliable way to never be killed is to run as an accessibility service. I haven't implemented this in Red Moon but will likely add it as an option. I believe it has a large impact on bettery life.
You can also set alarms using AlarmManager to restart the service if it has been killed, and optionally wake up the device. This is what DNS66 does.