You can prioritize services to reduce the likelihood that services will be terminated by the system. This is called a foreground service.
A foreground service is a service that is actively recognized by the user and is not considered a candidate for the system to abort in the event of low memory.
Even if a music app or exercise app leaves the app, it will be easy to understand if you think about how it runs in the background, showing the status of the app on the status bar.
Please read the Run Service in the foreground section of the document below to apply the code.
As it means that the service will die at the same time as the app ends, I think the service will work in the same process as the calling component.
From the service's onStartCommand, Try using returnSTART_STICKY
© 2024 OneMinuteCode. All rights reserved.