GMS :: LocationClient(Android)中的DeadObjectException
作者:互联网
在Android上,我们有一个包装来自GMS(Google移动服务)的LocationClient对象的类. (请注意,LocationClient实现了com.google.android.gms.common.GooglePlayServicesClient).
不幸的是,LocationClient对象习惯于抛出DeadObjectExceptions(例如当我们调用locationClient.getLastLocation()时),我们通过几种日志记录机制检测到它.然而,有点奇怪的是,LocationClient没有被记录为抛出DeadObjectExceptions,而且我只能捕获所说的DeadObjectExceptions大约1/40的时间o_0.我们没有这个问题的责备,我个人从未见过它,但它发生在我们的大量用户身上.
其他说明:
[a]什么是“引起:java.lang.IllegalStateException:android.os.DeadObjectException”这一行?这两种异常类型没有祖先 – 后代关系
[b]我发布到Android论坛,但当然他们拒绝我的帖子为“错误的论坛”,并且没有GMS论坛,所以我完全没有运气.
总而言之,问题是:GMS正在触发这个奇怪的无法捕获的异常,那么该怎么做呢?我该怎么办?
Here's a stack trace:
com.myapp.android.service.AsyncExecutionException
at com.myapp.android.service.AsyncService$ExceptionThrower.run(MyApp:120)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4794)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.IllegalStateException: android.os.DeadObjectException
at com.google.android.gms.internal.ey.getLastLocation()
at com.google.android.gms.internal.ez.getLastLocation()
at com.google.android.gms.location.LocationClient.getLastLocation()
***at com.myapp.GoogleLocationProvider.getLastLocation(MyApp:92)***
at com.myapp.LocationProducer.getLocation(MyApp:183)
at com.myapp.LocationProducer.getLocationHeader(MyApp:194)
at com.myapp.API.onExecute(MyApp:344)
...
at java.lang.Thread.run(Thread.java:856)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Binder.java)
at com.google.android.gms.internal.ex$a$a.a()
at com.google.android.gms.internal.ey.getLastLocation()
at com.google.android.gms.internal.ez.getLastLocation()
***at com.google.android.gms.location.LocationClient.getLastLocation()***
at com.myapp.GoogleLocationProvider.getLastLocation(MyApp:92)
at com.myapp.LocationProducer.getLocation(MyApp:183)
at com.myapp.LocationProducer.getLocationHeader(MyApp:194)
...
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
———— ADDENDUM ————-
这是我们的实际代码.您会注意到我们总是事先检查是否有mLocationClient.isConnected(),所以这不是问题.我们可能会非常不走运,并且在调用isOnConnected()和getLastLocation()之间就会死掉mLocationObject,但这对我来说似乎不太可能.我想我可以在呼叫之前,之间和之后开始记录并找出答案.
LocationClient mLocationClient; // populated somewhere
public Location getLastLocation() {
if (!mLocationClient.isConnected()) {
return null;
}
Location location = null;
try {
location = mLocationClient.getLastLocation();
} catch (Exception e) {
if (!handleDeadObjectException(e)) {
throw e;
}
}
return location;
}
// logs, attempts to handle depending on user configuration
private boolean handleDeadObjectException(Exception e);
解决方法:
The object you are calling has died, because its hosting process no longer exists.
意思是,您正试图在不再可用的不同进程中到达对象.例如,如果您绑定到在不同进程(即Google移动服务)中运行的服务,则您使用的IBinder是一个“代表”远程进程中的对象的本地对象.当远程对象不再可用,并且您尝试使用本地IBinder对象时,您将获得DeadObjectException.
所以…
a] what is the line “Caused by: java.lang.IllegalStateException: android.os.DeadObjectException” about? Those two Exceptions types do not have an ancestor-descendant relationship
这两个例外没有任何关联. IllegalStateException是实际异常,DeadObjectException是根异常.
由于gms.location.LocationClient.getLastLocation()不希望声明抛出内部实现的throw元素 – 使用绑定器等 – 它根本不这样做.但是当发生诸如DeadObjectException之类的异常时,它仍然想要抛出,因此它使用运行时异常IllegalStateException(它不需要throw声明).
[b] I posted to the Android forum, but of course they rejected my post as ‘wrong forum,’ and there’s no GMS forum so I’m totally out of luck.
标签:android,location-client 来源: https://codeday.me/bug/20190722/1506639.html