Android Dead Object Exception

江枫思渺然 提交于 2019-11-28 00:52:51

This is not a memory leak problem. Definition of the memory leak (from Wikipedia):

A memory leak, in computer science (or leakage, in this context), occurs when a computer program acquires memory but fails to release it back to the operating system.

Here, you have an opposite case - memory is freed before it should (at least from your program's point of view).

From developer.android.com:

DeadObjectException extends RemoteException

The object you are calling has died, because its hosting process no longer exists.

For example:

You have MyActivity and MyService classes. You use Handler/Messenger to communicate between them. You create Handler and Messenger in MyActivity, and then send created instance of Messenger to MyService via Intent. Then you do some stuff, time passes, and your MyActivity gets destroyed, together with it's Handler and Messenger. Now, if you don't handle that well, MyService won't know that Messenger that he has is not valid anymore, so, he tries to send something through it, and get DeadObjectexception:

/* Send a Message to this Messenger's Handler.

Parameters:

message The Message to send. Usually retrieved through Message.obtain().

Throws:

RemoteException Throws DeadObjectException if the target Handler no longer exists.*/

public void send(Message message) throws RemoteException {...}

If You are calling any function from Native Library(.so file), Just check the package name used while creating JNI function is same as you are declaring native method in Java class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!