Ad

Cannot Resolve Method UpdateUI()

- 1 answer

I'm trying to add a google login with firebase to my project, following the offical documentation for google sign-in.

https://developers.google.com/identity/sign-in/android/sign-in

I already seen other questions but no one can resolve my problem. I don't understand if I have to create my own updateUI() method or I have to add some libraries, and if I have to write it, what I have to do. The code is short and simply

package com.database.gabriele.databasefb;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.firebase.auth.FirebaseAuth;


public class MainActivity extends AppCompatActivity {

    SignInButton button;
    FirebaseAuth mAuth;
    private final static int RC_SIGN_IN = 2;
    GoogleSignInClient mGoogleSignInClient;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();

        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

        button = (SignInButton) findViewById(R.id.sign_in_button);
    }

    @Override
    protected void onStart()
    {
        super.onStart();
        GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
        updateUI(account);
    }
}

When I try to run the code, it return me the error "Cannot resolve method updateUI(...)"

Ad

Answer

That's because you don't have this method in your class, you need to create it according to your needs. The documentation only mentioned that you need to do some UI updates when the application starts.

For example, check if the user already logged in or not and do something accordingly :

//Change UI according to user data.
public void updateUI(FirebaseUser account){

    if(account != null){
        Toast.makeText(this,"You Signed In successfully",Toast.LENGTH_LONG).show();
        startActivity(new Intent(this,AnotherActivity.class));

    }else {
        Toast.makeText(this,"You Didnt signed in",Toast.LENGTH_LONG).show();
    }

}
Ad
source: stackoverflow.com
Ad