Cannot Resolve Method UpdateUI()
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(...)"
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();
}
}
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM