Google Sign In flow with multiple activities

Viewed 885

I have an app with 3 activities : a login activity, a main activity and a detail activity.

The login activity uses Google Sign In to get the account of the user (the token id and the email). Both Main activity and Detail activity need theGoogleSignInAccount.

I don't want to the app to always start on login activity and transparently re-login when the user launch back the app.

I don't want to store the token id and the user email on shared preferences, I'd prefer to manipulate directly aGoogleSignInAccount everywhere in my app.

What is the proper flow to handle this sign in scenario ? Should I try to do a silentSignIn in every screen or is there a better way to store and retrieve the GoogleSignInAccount ?

2 Answers

You can also pass GoogleSignInAccount as extra Intent input:

GoogleSignInAccount acct = result.getSignInAccount();
Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("singedInAccount", acct);
startActivity(intent);

and receive it in onCreate() another's activity method as such:

getIntent().getParcelableExtra("singedInAccount");

Notice that you have to use getParcelableExtra() instead of getSerializableExtra() as far as GoogleSignInAccount implements Parcelable and not Serializable interface.

Related