Button to open a new Activity is returning to the initial Activity

Asked

Viewed 598 times

-1

In my application I made a login screen and put a button to authenticate the user through Facebook, after logging in the main screen and on this screen has a button that calls a new Activity. So far so good. Now the problem, went to put a button on the login screen to authenticate the user by Google, he logs in and opens the main screen, the same as the login with Facebook, but when I click on the button to open the new Activity instead of opening the new screen is going back to the login screen

Button code Da Mainactivity

  Button Config= (Button) findViewById(R.id.Config);
            PerfilButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(MainActivity.this,Config.class));

                }
            });

Code to open the main activity

private void goMainScreen() {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

That one goMainScreen() is used to call the main screen after the user logs in by Google

When logging in with Facebook everything works well, but when logging in with Google gives problem when clicking the button to open the new Activity.

I think the error may be on the button, but I don’t understand why it works well when logging in with Facebook but not with Google, if the two ways of logging in open the same screen

  • The problem may even be in the button, but if it works with one and not the other, possibly the issue is in the integration of Google login. In the first snippet, you declare the button Config, but defines the PerfilButton. Maybe you need to expose more code to make it clear.

1 answer

0

Try it like this

Button Config= (Button) findViewById(R.id.Config);
    PerfilButton.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, Config.class)
            startActivity(i);

        }
    });
  • Thanks for the help, but I discovered the problem and it wasn’t on the button, it was on user authentication. By clicking on the button the new Activity performs a query in the register to fetch the user information, as it was already logged in when performing the query.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.