Android notificationlistenerservice app unwanted restart

69 Views Asked by At

If you build an app that interface with notificationlistenerservice, for example:

https://github.com/Chagall/notification-listener-service-example.git

if you kill the app for example interrupting debug in Android Studio, than the app is restarted automatically:

this is an example of the logcat

very easy to reproduce, clone the module above, compile, debug and stop debugging

if you comment service definition in manifest file:

service definition commented

this behaviour, that sometimes prevent a new debug session to start, disappear

there is somebody that can state if this is correct ?

i saw other post where people ask if it's possible to stop notificationlistenerservice:

How to stop NotificationListenerService android?

really I think the solution should be the Android system unbind from the service and let him free to stop

1

There are 1 best solutions below

1
Maurizio Vivarelli On

I found the solution, in effect there is a method that ask the "android runtime" to unbind from your service:

https://developer.android.com/reference/android/service/notification/NotificationListenerService#requestUnbind()

the only place where I found it was the official documentation