I would like to start the service only when I return from the currently open screen (MainActivity) or press the Home button to do something else, and give notifications every certain time.
When I go back to the app, I feel like I'm going to stop the service stop.
If anyone knows how to do it, please take care of me.
Simply
Run startService() in Activity.onPause()
Run stopService() in Activity.onResume()
Can't we?
話It's a little off topic, but
The startService() may automatically terminate from the Android system.
You can use startForeground() to suppress automatic termination in a significant number of situations, but
Notification indicates that the service is starting.
© 2024 OneMinuteCode. All rights reserved.