Search code examples
androidandroid-serviceandroid-lifecycleondestroy

How do I end a service only when I exit the app?


I have a service I want to run the second the app opens, and only want this service to end as soon as the user exits the app. How do I program those two things?


Solution

  • use StartService in onCreate of the activity and in onexit button onclicklistener use stopService