Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run new gms Task object synchronously like PendingResult.await?

I don't see any await synchronous api on com.google.android.gms.tasks.Task. Am I missing something? I am trying to migrate to use the new *Client classes in Play services. I already designed my code to run in another thread and use PendingResult.await. My code was like this:

val pendingResult = Auth.GoogleSignInApi.silentSignIn(TwinkleApplication.instance.gapiClient)
val account = pendingResult.await(10, TimeUnit.SECONDS)

I wish to use this, but don't know how to continue.

    val signin = GoogleSignIn.getClient(ctx, Global.getGSO())
    val task = signin.silentSignIn()
like image 341
androidguy Avatar asked Aug 24 '18 02:08

androidguy


1 Answers

The Tasks class includes a static await method - in Java I'm doing this:

GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(context, gso);

Task<GoogleSignInAccount> task = googleSignInClient.silentSignIn();

try {
    GoogleSignInAccount account = Tasks.await(task);
    ...
} catch (ExecutionException e) {
    // task failed
} catch (InterruptedException e) {
    // an interrupt occurred while waiting for the task to finish
}
like image 130
gregdev Avatar answered Jan 13 '23 08:01

gregdev