13

I'm getting a frequent crash with the log below. It doesn't reference my application code but I'm guessing it may have something to do with GoogleApiClient connecting/disconnecting. Anyone get anything similar to this? I haven't been able to find anything on here.

java.lang.IllegalStateException: android.os.DeadObjectException
  at com.google.android.gms.internal.ao.removeAllListeners(Unknown Source)
  at com.google.android.gms.internal.ap.disconnect(Unknown Source)
  at com.google.android.gms.common.api.b.n(Unknown Source)
  at com.google.android.gms.common.api.b.a(Unknown Source)
  at com.google.android.gms.common.api.b$2.onConnectionSuspended(Unknown Source)
  at com.google.android.gms.internal.r.y(Unknown Source)
  at com.google.android.gms.internal.q$a.handleMessage(Unknown Source)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5102)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.DeadObjectException
  at android.os.BinderProxy.transact(Native Method)
  at com.google.android.gms.internal.an$a$a.a(Unknown Source)
  ... 15 more

Possibly where it's happening. I added a try/catch to catch the exception

mGApiClientMgr.addTask(mGApiClientMgr.new GoogleApiClientTask() {
            @Override
            public void run() {
                Log.d(LOG_TAG, "Refreshing data set.");
                Location location;
                try {
                    location = LocationServices.FusedLocationApi.getLastLocation(getGoogleApiClient());
                    onLocationChanged(location);
                }
                catch(IllegalStateException ex) {
                    // TODO
                }
            }
        });

where addTask does:

  private final LinkedBlockingQueue<GoogleApiClientTask> mTaskQueue = new LinkedBlockingQueue
        <GoogleApiClientTask>();

  mTaskQueue.offer(task);
ono
  • 2,984
  • 9
  • 43
  • 85
  • can you show code snippet of your gms listeners – ashoke Oct 06 '14 at 16:44
  • This is the closest thing I've found http://stackoverflow.com/questions/24288685/deadobjectexception-in-gmslocationclient-android – ono Oct 06 '14 at 16:52

1 Answers1

7

This seems related to handlers and message passing...Based on below snippet from your stack trace, gms is seeing a DeadObjectException when trying to process a message on the looper. Even though the stack trace shows gms related, it could have be triggered by your code.

   at com.google.android.gms.internal.q$a.handleMessage(Unknown Source)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)

This exception is seen if the message its trying to access belong to a process that has since exited/killed. Do a code search for all handler sendMessage* message dispatch calls, through out your code. Even this may not catch all instances as some gms calls could result in handler message dispatches.

Also, check if any of your background services, or activities that allocated handler messages, are exiting. Android could be destroying them depending on life cycle states, try overriding onDestroy.

In all your activities/services, any where you make calls to gms api, check the objects you create and pass to gms; If they die, those objects are not valid any more.

Community
  • 1
  • 1
ashoke
  • 6,441
  • 2
  • 26
  • 25
  • Thanks for that info. Assuming the `sendMessage` is causing it, can I just wrap each of them with a try-catch to catch the IllegalStateException? – ono Oct 08 '14 at 21:41
  • that wont help as `sendMessage` is just going to hand over the object to Message queue and return. The exception is happen at much later time, when `gms` pulls the object from Message queue. Mean while, the sender may have exited or killed by android life cycle. make sure you allocate object on a higher scope or see if you can retain. – ashoke Oct 08 '14 at 21:47
  • A potential solution is to detect what Activity has been destroyed that is related to the object passed between the Activity and the Service via a Handler. Or identify the Service that is causing it and stop the service when the Activity is destroyed. Is this the way to go about it? – ono Nov 03 '14 at 22:34
  • @ono yep, certainly helps if you can put in checks to detect leaks and handle them – ashoke Nov 04 '14 at 00:17