android - Google Drive API await() UI Thread Error -


I am implementing the Google Drive API in my Android application. I do not want to use PendingResult # setResultCallback () Rather, I want to use PendingResult # await () so that I can get the result in the next line and do not wait it is not an issue because everything in the background is going on.

However, every time I wait (), I get the following error I have tried to run a call on the Google Drive API that serves as an AsyncTask, Thread, IntentService, AsyncTask and one Uses the wait () in the service with the thread. I have received the following error every time I tried to apply the thread to Looper.prepare (), but he did not solve anything.

Does anyone else have this problem?

  java.lang IllegalStateException: should not be made to call on the UI thread at com.google.android.gms.internal.hm.a to wait (unknown source) com.google.android connect .gms.common.api.a at $ a.await on (unknown source) [OMITTED] on .GoogleDriveManager $ 2.oncom.google.android.gms.internal.hc.c (GoogleDriveManager.java:83) to com (Unknown source) at .google.android.gms.common.api.c Com.google.android.gms.common.api.cd (unknown source) at com.google.android.gms.common.api.c $ 2.on (unknown source) connected on com.google.android (Unknown sources ) Com.google.android.gms.internal.hc.cp (unknown source) at com.google.android.gms.internal.hb $ hb (unknown source) .gms.internal.hc.c (unknown source) com At com.google.android.gms.internal.hb $ a.google.android.gms.internal.hb $ hd (unknown source) at com.google.android.gms.internal.hb $ b.fv (unknown source) ) .handleMessag Android.os.Handler.dispatchMessage at E. (Unknown Source) and Android.OSLopper. Omitted (Looper.java:1236) on android.app.ActivityThread.main (ActivityThread.javaitter146) on java.lang.reflect.Method.invoke on Java.lang.reflect.Method.invoke Native (Native Method) (method.java Less15) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 796) at com.android.internal.os.jygoteInit.main (ZygoteInit.java:612) at Dalvik.system.NativeStart.main (Basic Law)   

in order to test the API I code:

  apiClient = new GoogleApiClient.Builder (mContext) .addApi (Drive. API) .addScope (Drive.ScopeE_APPFOLDER) .addConnectionCallbacks (New GoogleApiClient.ConnectionCallbacks () {@Unput the public null at Connected (bundle bundle) {LogUtil.log (TAG, "On-Connect ()"); Thread = true; DriveApi.ContentsResult Results = Drive.DriveApi.newContents (apiClient). Await ();} Overlap public blank on connection aspended (intI) {LogUtil.log (tag, "On Connection Connection ()"); Connected = wrong;}}) AddOnConnectionFailedListener (new GoogleApiClient.OnConnectionFailedListener {@OverrideConnectation public void (connection relationship results) {LogUtil.log (tag, "on connection ()"); connected = false;}}) .build (); ApiClient.connect ();    

apiClient.connect () is an incompatible operation, Therefore, why not calling it within an async task does not help (connecting to the background thread does not help when onconnected () is being called on the UI thread).

Instead, have your onconnected () callback - that AsyncTask of doInBackground () and Drive You can call. DriveApi.newContents (apiClient). Await () .

Of course, there is no need to call await () any time - wait for asynchronous to complete newContents () : Override public null on / P>

  @connected (bundle bundle) {LogUtil.log (TAG, "on-connect ()"); Connected = true; Drive.DriveApi.newContents (apiClient) .setResultCallback (New result callback & lt; DriveApi.ContentsResult & gt; () {@Override Results on Public Zero (DriveApi.ContentsResult Results) {// Use Results}}); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -