DriveServiceHelper cannot be cast to Parcelable

Viewed 58

I have an android app which makes the sign in process at the start in order to permit the user to save the files in a google drive folder. Now, I would like to pass the DriveServiceHelper object through the activities so I don't need to make again the sign in process, but I get the error:

java.lang.ClassCastException: DriveServiceHelper cannot be cast to android.os.Parcelable How can I solve it? This is my sign in process:

private void requestSignIn() {
    Log.d(TAG, "Requesting sign-in");
    GoogleSignInOptions signInOptions =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
                    .build();
    GoogleSignInClient client = GoogleSignIn.getClient(this, signInOptions);
    // The result of the sign-in Intent is handled in onActivityResult.
    startActivityForResult(client.getSignInIntent(), REQUEST_CODE_SIGN_IN);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    switch (requestCode) {
        case REQUEST_CODE_SIGN_IN:
            if (resultCode == this.RESULT_OK && resultData != null) {
                handleSignInResult(resultData);
            }
            break;
    }

    super.onActivityResult(requestCode, resultCode, resultData);
}

private void handleSignInResult(Intent result) {
    GoogleSignIn.getSignedInAccountFromIntent(result)
            .addOnSuccessListener(googleAccount -> {
                Log.d(TAG, "Signed in as " + googleAccount.getEmail());
                // Use the authenticated account to sign in to the Drive service.
                GoogleAccountCredential credential =
                        GoogleAccountCredential.usingOAuth2(
                                this, Collections.singleton(DriveScopes.DRIVE_FILE));
                credential.setSelectedAccount(googleAccount.getAccount());
                Drive googleDriveService =
                        new Drive.Builder(
                                AndroidHttp.newCompatibleTransport(),
                                new GsonFactory(),
                                credential)
                                .setApplicationName("Drive API Migration")
                                .build();

                mDriveServiceHelper = new DriveServiceHelper(googleDriveService);
            })
            .addOnFailureListener(exception -> Log.e(TAG, "Unable to sign in.", exception));
}

This is how I'm passing the mDriveServiceHelper (which calls the method I need):

myIntent.putExtra("driver", (Parcelable) mDriveServiceHelper);
0 Answers
Related