{"action":"created","issue":{"url":"https://api.github.com/repos/googlecast/CastCompanionLibrary-android/issues/170","labels_url":"https://api.github.com/repos/googlecast/CastCompanionLibrary-android/issues/170/labels{/name}","comments_url":"https://api.github.com/repos/googlecast/CastCompanionLibrary-android/issues/170/comments","events_url":"https://api.github.com/repos/googlecast/CastCompanionLibrary-android/issues/170/events","html_url":"https://github.com/googlecast/CastCompanionLibrary-android/issues/170","id":68166438,"number":170,"title":"Crash when disconnecting wifi","user":{"login":"path2727","id":3408212,"avatar_url":"https://avatars.githubusercontent.com/u/3408212?v=3","gravatar_id":"","url":"https://api.github.com/users/path2727","html_url":"https://github.com/path2727","followers_url":"https://api.github.com/users/path2727/followers","following_url":"https://api.github.com/users/path2727/following{/other_user}","gists_url":"https://api.github.com/users/path2727/gists{/gist_id}","starred_url":"https://api.github.com/users/path2727/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/path2727/subscriptions","organizations_url":"https://api.github.com/users/path2727/orgs","repos_url":"https://api.github.com/users/path2727/repos","events_url":"https://api.github.com/users/path2727/events{/privacy}","received_events_url":"https://api.github.com/users/path2727/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-13T18:48:57Z","updated_at":"2015-04-22T00:39:21Z","closed_at":null,"body":"\r\nSteps\r\n\r\n1) connect to chromecast receiver\r\n2) play a video (plays on receiver)\r\n3a) put android device in airplane mode  or disable wifi\r\n4) attempt to play another video ( i think the crash happens on #3 though, i am just trying to play another video by chance)\r\n\r\nIt doesn't reproduce 100% of the time.\r\n\r\nI want to add code to catch this exception.\r\n\r\njava.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.\r\nat com.google.android.gms.common.internal.zzk.zzfc(Unknown Source)\r\nat com.google.android.gms.common.internal.zzk.zzjb(Unknown Source)\r\nat com.google.android.gms.internal.zzju.disconnect(Unknown Source)\r\nat com.google.android.gms.common.api.zzd.zzao(Unknown Source)\r\nat com.google.android.gms.common.api.zzd.disconnect(Unknown Source)\r\nat com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager.disconnectDevice(BaseCastManager.java:262)\r\nat com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager.onDeviceSelected(BaseCastManager.java:204)\r\nat com.google.android.libraries.cast.companionlibrary.cast.CastMediaRouterCallback.onRouteUnselected(CastMediaRouterCallback.java:64)\r\nat android.support.v7.media.MediaRouter$GlobalMediaRouter$CallbackHandler.invokeCallback(MediaRouter.java:2480)\r\nat android.support.v7.media.MediaRouter$GlobalMediaRouter$CallbackHandler.handleMessage(MediaRouter.java:2427)\r\nat android.os.Handler.dispatchMessage(Handler.java:102)\r\nat android.os.Looper.loop(Looper.java:135)\r\nat android.app.ActivityThread.main(ActivityThread.java:5221)\r\nat java.lang.reflect.Method.invoke(Native Method)\r\nat java.lang.reflect.Method.invoke(Method.java:372)\r\nat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)\r\nat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)"},"comment":{"url":"https://api.github.com/repos/googlecast/CastCompanionLibrary-android/issues/comments/94984335","html_url":"https://github.com/googlecast/CastCompanionLibrary-android/issues/170#issuecomment-94984335","issue_url":"https://api.github.com/repos/googlecast/CastCompanionLibrary-android/issues/170","id":94984335,"user":{"login":"path2727","id":3408212,"avatar_url":"https://avatars.githubusercontent.com/u/3408212?v=3","gravatar_id":"","url":"https://api.github.com/users/path2727","html_url":"https://github.com/path2727","followers_url":"https://api.github.com/users/path2727/followers","following_url":"https://api.github.com/users/path2727/following{/other_user}","gists_url":"https://api.github.com/users/path2727/gists{/gist_id}","starred_url":"https://api.github.com/users/path2727/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/path2727/subscriptions","organizations_url":"https://api.github.com/users/path2727/orgs","repos_url":"https://api.github.com/users/path2727/repos","events_url":"https://api.github.com/users/path2727/events{/privacy}","received_events_url":"https://api.github.com/users/path2727/received_events","type":"User","site_admin":false},"created_at":"2015-04-22T00:39:21Z","updated_at":"2015-04-22T00:39:21Z","body":"i imported the ccl as a library in my project\r\n\r\nhere is where it was crashing\r\n\r\nhttps://github.com/googlecast/CastCompanionLibrary-android/blob/master/src/com/google/android/libraries/cast/companionlibrary/cast/BaseCastManager.java#L262\r\n\r\n wrapped the disconnect call with an isConnected check (only disconnect if connected).\r\n\r\nthen just to be sure, i caught an exception\r\n\r\nhere is my fix\r\n\r\n            if( mApiClient.isConnected()) {\r\n                try {\r\n                    mApiClient.disconnect();\r\n                } catch( Exception e ) {\r\n                    LOGE(TAG, \"error\", e);\r\n                }\r\n            }\r\n\r\n"}}