Skip to content

Added a QUIT Button in Notifications to close the Background Services

Anjani Kumar requested to merge (removed):master into master


This merge request adds a button "QUIT" to the notification of the app which when tapped stops all the background services except the NotificationReceiver. A new BroadcastReceiver named QuitRequestReceiver receives the call when "QUIT" button is tapped which calls stopService() on and It also calls cancelAll() on the NotificationManager.

This is required because if the user is sure that his/her PC is switched-off then also these services are running in the Background. And if the user has not disabled the persistent notification then it becomes very annoying to see the notification all the time. Exiting the app properly when user is sure that he/she is not going to use the app will love this feature. All services can be started again by opening the app.

This stops all the services except NotificationReceiver as Android API's don't provide any method to stop NotificationListener. This merge request is inspired by this.

Test Plan

To test this patch, close the app from pressing home or clearing the app from recent apps. Then if the persistent notification setting is on, then press "QUIT" button in the notification and it will stop the stated BackgroundServices and present a Toast saying "Background Service Stopped." when everything went fine.

Edited by Anjani Kumar

Merge request reports