0

My app keeps stopping and I am guessing its because of this warning.

startActivityForResult(android.content.Intent, int) is deprecated.

I do not understand why this happens and it's confusing me. Could it be my dependancies?

Screenshot here

public class MainActivity extends AppCompatActivity {

    
    private static final int SIGN_IN_REQUEST_CODE = 123;

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

        if(FirebaseAuth.getInstance().getCurrentUser() == null) {
            // Start sign in/sign up activity
            startActivityForResult(
                    AuthUI.getInstance()
                            .createSignInIntentBuilder()
                            .build(),
                    SIGN_IN_REQUEST_CODE
            );
        } else {
            // User is already signed in. Therefore, display
            // a welcome Toast
            Toast.makeText(this,
                    "Welcome " + FirebaseAuth.getInstance()
                            .getCurrentUser()
                            .getDisplayName(),
                    Toast.LENGTH_LONG)
                    .show();

            // Load chat room contents
            displayChatMessages();
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == SIGN_IN_REQUEST_CODE) {
            if(resultCode == RESULT_OK) {
                Toast.makeText(this,
                        "Successfully signed in. Welcome!",
                        Toast.LENGTH_LONG)
                        .show();
                displayChatMessages();
            } else {
                Toast.makeText(this,
                        "We couldn't sign you in. Please try again later.",
                        Toast.LENGTH_LONG)
                        .show();

                // Close the app
                finish();
            }
        }

    }
    private void displayChatMessages() {
    }


}
Doug Stevenson
  • 268,359
  • 30
  • 341
  • 380
KD1
  • 11
  • 2
  • 1
    *Deprecated* stuff is just things that are going to be removed at some point in the future, so you should move away from using them. It's just an advisory warning, it won't crash the app - the method still exists, it still works! You need to look in *LogCat* to see the error message and stacktrace - that will tell you why it's crashing – cactustictacs May 01 '22 at 19:51

0 Answers0