The application authorizes the user (at the first login) via google, using fireBase.
The first launch of the application, authorize the user. On subsequent logins, redirect the user to the main Activity (if it is authorized) without showing the authorized activity.
SharedPreferences is not suitable.
Please do not throw stones at colleagues. I'm just learning android and I really need the advice of more experienced comrades. thank
public static final int SIGN_IN_CODE = 777; private GoogleApiClient googleApiClient; private ActivityMainBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); binding = DataBindingUtil.setContentView(this, R.layout.activity_main); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); googleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); binding.buttonGoogle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); startActivityForResult(intent, SIGN_IN_CODE); } }); } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == SIGN_IN_CODE) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); handleSignInResult(result); } } private void handleSignInResult(GoogleSignInResult result) { if (result.isSuccess()) { goMapScreen(); } else { Toast.makeText(this, R.string.not_log_in, Toast.LENGTH_SHORT).show(); } } private void goMapScreen() { Intent intent = new Intent(this, ScreenMapActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }