I don’t want the notification service to be working while the user is in the application. As of right now I have it starting in the onCreate and onResume methods and stopping in the onPause method. Is that correct?
Also, is it sufficient to specify the intent and execute stopService(intent) to stop it? There isn’t a direct relationship between the start and stop methods except they reference the same class.
Thank you for any help.
Here is the activity lifecycle.
As you will see,
onCreate()andonResume()are called before the activity is created so you do not want to start your notification service there. You should stop it instead. It is a good idea to do it once inonResume()because it is the entry point of your activity.onPause()is where user navigates away from the activity so it is where you will want to start the service again.