Java android.os.deadobjectexception 在服务 android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21983058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android.os.deadobjectexception in service android
提问by user3243651
I have an application wich take data values (coordinates) from a service, and works fine but when elapse about 7/8 minutes crash.
我有一个应用程序,它从服务中获取数据值(坐标),并且工作正常,但是大约 7/8 分钟后崩溃。
In logcat appears a lot of this messages:
在 logcat 中出现了很多这样的消息:
02-24 09:50:35.761: E/RemoteException(6395): android.os.DeadObjectException
these messages are from the application not service, but i supose that is because service fails no?
这些消息来自应用程序而不是服务,但我认为这是因为服务失败,不是吗?
some help??
一些帮助??
thanks
谢谢
[UPDATE]
[更新]
with the comments i understand better that the problems is caused by service's fail, but i read this question How to fix android.os.DeadObjectException android X(similar to mine) but the answer.... is some confuse to me..
通过评论,我更好地理解问题是由服务失败引起的,但我读了这个问题如何修复 android.os.DeadObjectException android X(类似于我的)但答案.... 对我来说有些困惑..
this is my ondestroy():
这是我的 ondestroy():
@Override
public void onDestroy() {
Toast.makeText(this, "Servicio destruido", Toast.LENGTH_SHORT).show();
Log.d("SERVICEBOOT", "Servicio destruido");
capture.control(0);
}
how can i know wich element close my service??
我怎么知道哪个元素关闭了我的服务?
thanks again
再次感谢
采纳答案by Ana
you are using the instance of an object that no longer exist in memory as parent process is stopped.
当父进程停止时,您正在使用内存中不再存在的对象实例。
回答by Vithu
Add this in Service Class. This will stop the app from crashing. 'onTaskRemoved' triggers when app is removed from ram
在服务类中添加它。这将阻止应用程序崩溃。'onTaskRemoved' 在应用程序从 ram 中删除时触发
@Override
public void onTaskRemoved(Intent rootIntent){
stopSelf();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
super.onTaskRemoved(rootIntent);
}
@Override
public void onDestroy() {
super.onDestroy();
//Your Runnable
mRunnable=null;
}