First look at the official explanation:
- The Linktodeath () method can be used to register a ibinder.deathrecipient with the IBinder, which would be called if its containing process goes away.
That is, after we have applied for a service binder through Systemservice, we can call this IBinder's Linktodeath function to register. You can register an object of type Ibinder.deathrecipient. Where Ibinder.deathrecipient is an embedded class defined in the IBinder class.Public abstract void linktodeath (ibinder.deathrecipient recipient, int flags) SINCE:API Level 1
Register the recipient for a notification if this binder goes away. If This binder object unexpectedly goes away (typically because its hosting process have been killed), then the given Ibind Er. Deathrecipient ' s deathrecipient.binderdied () method would be called.
You'll only receive death notifications for remote binders, as local binders by definition can ' t die without You dying a s well.
When the service process corresponding to this ibinder is exited abnormally, such as being killed, the system invokes the Binderdied function of the Deathrecipient class object that was registered with Linktodeath before the IBinder.
In the general implementation, the BP terminal will register Linktodeath, the purpose is to listen to the bound service exception exits, the general binderdied function is used to release some related resources.
Linktodeath Introduction to Android IBinder