Search code examples
androidgoogle-play-servicesgoogle-drive-android-api

Is there any way make account picker UI appear as fast as possible


Currently, I'm migrating from API Client Library for Java to Drive API for Android

However, compared with API Client Library for Java's, I realize the account picker from Drive API for Android are very slow. Sometimes, it takes up to 5 seconds waiting time.

Very fast (API Client Library for Java)

private static final GoogleAccountCredential googleAccountCredential = GoogleAccountCredential.usingOAuth2(context, 
    Arrays.asList(
        DriveScopes.DRIVE_APPDATA,
        // Legacy. Shall be removed after a while...
        DriveScopes.DRIVE
    )
);

startActivityForResult(googleAccountCredential.newChooseAccountIntent(), RequestCode.REQUEST_ACCOUNT_PICKER_LOAD_FROM_CLOUD);

enter image description here

This account picker appears almost instantly.


Very slow (Drive API for Android)

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(context)
    .addApi(Drive.API)
    .addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

mGoogleApiClient.connect();

@Override
public void onConnectionFailed(ConnectionResult result) {
    Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
    if (!result.hasResolution()) {
        // show the localized error dialog.
        GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(), 0).show();
        return;
    }
    try {
        result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
    } catch (SendIntentException e) {
        Log.e(TAG, "Exception while starting resolution activity", e);
    }
}

enter image description here

Usually, when I invoke the account picker for the first time, it takes quite a long time to wait. Sometimes, the waiting time can take up to 5 seconds.

I understand that our application code invoke Google Play Services via IPC. Hence, there might be some slowness. However, I don't expect it to be as slow as up to 5 seconds.

Is there any thing I can do, to make account picker UI appear as fast as possible?


Solution

  • As described by @seanpj in https://stackoverflow.com/a/34706726/72437

    startActivityForResult(AccountPicker.newChooseAccountIntent(null,
        null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null),
        REQ_ACCPICK);
    

    will be much faster.

    One of the reason, it doesn't show your profile picture in the pop up dialog. I believe those profile pictures required network activities, which make the process slow.