On Android you can use a bound foreground service and keep it running into perpetuity.
Must bind/start with applicationContext
No need for requesting user opt out of battery optimizations
This is what kmp-tor does
https://kmp-tor.matthewnelson.io/library/runtime-service/io.matthewnelson.kmp.tor.runtime.service/-tor-service-config/-builder-scope/stop-service-on-task-removed.html