1

I've been trying run the app through the emulator in Android Studio but it keeps on crashing, I figured this may be because the startActivityForResult is deprecated. What should be the new format for this?

private void signIn() {
        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);

Here's the full activity:

public class MainActivity extends AppCompatActivity {

SignInButton signin;
private GoogleSignInClient mGoogleSignInClient;
static final int RC_SIGN_IN = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    requestGoogleSignIn();
    signin.setOnClickListener(view -> signIn());



}
private void requestGoogleSignIn()
{
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}

private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

}

Rafael Campos
  • 49
  • 1
  • 5
  • 1
    Deprecation does not mean that you cannot use `startActivityForResult` - the crash is probably caused by another reason. Can you share the stack? – Shlomi Katriel Aug 24 '21 at 07:40
  • 1
    If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Please respond with @AlexMamo – Alex Mamo Aug 24 '21 at 07:46
  • 1
    Have you setup SHA-1/SHA-256 and enabled Google sign-in in your firebase console? And also enabled google services for your app? – Dorian Pavetić Aug 24 '21 at 07:50
  • 1
    When ever there is a crash there is a stack trace, please include this so we can help you! – DevWithZachary Aug 24 '21 at 09:30
  • 1
    Question is already asked : https://stackoverflow.com/questions/68687402/startactivityforresult-deprecated-for-google-sign-in – Bolt UIX Sep 12 '21 at 14:59
  • @HariShankarS the question is in Kotlin, not Java – avs Mar 15 '22 at 22:43

0 Answers0