Android Question [SOLVED] how to detect if main app has been closed .

John Decowski

Member
Licensed User
I have an app with a background service. I am using the service to play sound in background. Problem is, is when you close the app manually, the service keeps playing sound in background. I have the service set to start every 10s and audibly play sound every 10s. The service schedules itself every 10s so , when the main activity is closed the service still goes on rescheduling. and yes i have watched the app life cycle tutorial.
 

John Decowski

Member
Licensed User
@Peter Simpson that does work to kill the service but, I need to kill the service when the main activity is killed unexpectedly.
because i need the service to still run if the home button is pressed.
 

mcqueccu

Active Member
Licensed User
Usually pressing back key twice should close the main activity and the app.

I have a radio streaming app which plays in the background with whena service you press the home button, but it has a notification icon which you can press to bring the main activity up and then close with back button.
 

John Decowski

Member
Licensed User
my concern is when the user opens the task chooser and quits app, my service stays running using data and other resources. I want to be able to catch the quit and close out the service.
 

Brandsum

Well-Known Member
Licensed User
You can track from starter service.
B4X:
Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
    StopService(<your service>)
End Sub
 

John Decowski

Member
Licensed User
You can track from starter service.
B4X:
Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
    StopService(<your service>)
End Sub
Thank you @Brandsum that is exactly what i was looking for! I've really never messed with services much and starter service either. Thank you!
 
Top