logout GoogleApiClient from another activity - java

I want build app with google account API. I done login with google tutorial and it work good but i try to logout account from another activity and it works too but method "onStart" in class LoginActivity.java login account back when i comment "onStart" its ok but when i try login again it login for account which was logged. For pass googleApiClient object to another activity i used singleton. Can you help me?
Code:
public void onStart() {
super.onStart();
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
Log.d(TAG, "Got cached sign-in");
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
showProgressDialog();
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
#Override
public void onResult(GoogleSignInResult googleSignInResult) {
hideProgressDialog();
handleSignInResult(googleSignInResult);
}
});
}
}
HomeActivity.java:
public class HomeActivity extends AppCompatActivity implements View.OnClickListener {
private GoogleApiClient mGoogleApiClient;// = state.getmGoogleApiClient();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
GlobalState state = ((GlobalState) getApplicationContext());
mGoogleApiClient = state.getmGoogleApiClient();
findViewById(R.id.sign_out_button).setOnClickListener(this);
}
private void signOut(){
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
GlobalState state = ((GlobalState) getApplicationContext());
state.setmGoogleApiClient(mGoogleApiClient);
Intent login = new Intent(getApplicationContext(), LoginActivity.class);
login.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
finish();
}
});
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.sign_out_button:
signOut();
break;
}
}

change onStart() with
#Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}

i resolve it by add onStart in HomeActivity:
#Override
protected void onStart() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClient.connect();
super.onStart();
}

Related

Can't get firebaseAuth.getCurrentUser() from a second activity (or fragments)

I need to get
FirebaseAuth.getInstance().getCurrentUser()
from a second activity "DetailActivity" but i've got a Null pointer :
Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
I can access it from the "MainActivity" but not from my bottomnavigationview fragments nor from the second activity "DetailActivity"
here is my code :
Connexion activity
public class ConnexionActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = ActivityConnexionBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());
mAuth = FirebaseAuth.getInstance();
setGoogleSignIn();
}
//////////////////////GOOGLE LOGIN
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// GOOGLE
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> mAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = mAccountTask.getResult(ApiException.class);
FirebaseAuthWithGoogleAccount(account);
} catch (ApiException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "OnClick: ERROR ACTIVITY RESULT NOT OK");
}
// FACEBOOK
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
private void FirebaseAuthWithGoogleAccount(GoogleSignInAccount account) {
Log.d(TAG, "firebaseauthwithgoogleaccount: begin firebase auth with google account");
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
#Override
public void onSuccess(AuthResult authResult) {
Log.d(TAG, "OnSuccess: Logged in");
// Get logged in user
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
// Get user info
String uid = firebaseUser.getUid();
String email = firebaseUser.getEmail();
Log.d(TAG, "OnSuccess: Email" + email);
Log.d(TAG, "OnSuccess: uid" + uid);
// Check if user is new or existing
if (Objects.requireNonNull(authResult.getAdditionalUserInfo()).isNewUser()) {
// User is new account created
Log.d(TAG, "OnSuccess: Account created...\n" + email);
Toast.makeText(ConnexionActivity.this, "Account created...\n" + email, Toast.LENGTH_SHORT).show();
} else {
// Existing user logged in
Log.d(TAG, "OnSuccess: Existing user... \n" + email);
Toast.makeText(ConnexionActivity.this, "Existing user...\n" + email, Toast.LENGTH_SHORT).show();
}
// Start MainActivity
startActivity(new Intent(ConnexionActivity.this, MainActivity.class));
finish();
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d(TAG, "OnFailure: Loggin failed" + e.getMessage());
}
});
}
private void setGoogleSignIn() {
// Configure google sign in
GoogleSignInOptions mGoogleSignInOption = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.requestidtoken))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, mGoogleSignInOption);
// Init firebase auth
mAuth = FirebaseAuth.getInstance();
}
//////////////////////GOOGLE END
FirebaseAuth.AuthStateListener mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
//Start main activity
startActivity(new Intent(ConnexionActivity.this, MainActivity.class));
Toast.makeText(ConnexionActivity.this,
"You successfully signed-in ", Toast.LENGTH_SHORT).show();
finish();
}
}
};
// #Override
// protected void onDestroy() {
//
// // FIREBASE LOGOUT
// FirebaseAuth.getInstance().signOut();
// // GOOGLE LOGOUT
// GoogleSignInOptions gso = new GoogleSignInOptions.
// Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).
// build();
//
// GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(ConnexionActivity.this, gso);
// googleSignInClient.signOut();
// // FACBOOK LOGOUT
// LoginManager.getInstance().logOut();
// super.onDestroy();
// }
MainActivity :
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = ActivityMainBinding.inflate(getLayoutInflater());
View view = mBinding.getRoot();
setContentView(view);
mAuth = FirebaseAuth.getInstance();
}
#Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser == null){
reload();
}
}
// restart connexion activity if the user isn't connected
private void reload(){
startActivity(new Intent(this, ConnexionActivity.class));
finish();
}
private void setBottomNavigationView(){
mBinding.bottomNavigation.setOnNavigationItemSelectedListener(navListener);
getSupportFragmentManager().beginTransaction().replace(mBinding.fragmentContainer.getId(), new MapFragment()).commit();
}
private final BottomNavigationView.OnNavigationItemSelectedListener navListener = item -> {
Fragment selectedFragment = null;
int itemId = item.getItemId();
if (itemId == R.id.map_view) {
selectedFragment = new MapFragment();
} else if (itemId == R.id.list_view) {
selectedFragment = new ListViewFragment();
} else if (itemId == R.id.workmates) {
selectedFragment = new WorkmatesFragment();
}
if (selectedFragment != null) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectedFragment).commit();
}
return true;
};
The fragment adapter where i launch the DetailActivity :
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
final Result restaurant = mRestaurants.get(position);
((ListViewViewHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Context context = view.getContext();
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra("idrestaurant", restaurant.getPlaceId());
context.startActivity(intent);
}
});
}
}
DetailActivty :
public class DetailActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = ActivityDetailBinding.inflate(getLayoutInflater());
View view = mBinding.getRoot();
setContentView(view);
}
private void setClickChosenRestaurantButton(){
mBinding.fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
Map<String, Object> chosenRestaurant = new HashMap<>();
chosenRestaurant.put("restaurantChosen", getRestaurantId());
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DocumentReference docRef = UserCallData.getAllUsers().getFirestore().collection("users").document(firebaseUser.getUid());
docRef.set(chosenRestaurant, SetOptions.merge()).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Log.d("123", "DocumentSnapshot successfully written!");
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d("123", "Error writing document", e);
}
});
}
else {
Log.d("123", "pb with firebaseauth!");
}
}
});
}
}
D/123: pb with firebaseauth!
To be honest i do not understand in detail the behavior of the Firebase auth system that's why i'm stuck here.
Any idea?
I found out why it doesn't work :
#Override
protected void onDestroy() {
// FIREBASE LOGOUT
FirebaseAuth.getInstance().signOut();
// GOOGLE LOGOUT
GoogleSignInOptions gso = new GoogleSignInOptions.
Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).
build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(ConnexionActivity.this, gso);
googleSignInClient.signOut();
// FACBOOK LOGOUT
LoginManager.getInstance().logOut();
super.onDestroy();
}
In my ConnectionActivity
This disconnected my FirebaseUser when i destroyed ConnexionActivity after each connexion of the user.
I switch it to my MainActivity which isn't destroyed until the app crash or the user forces it to close.

The email address is badly formatted Firebase/ android project

hi i am working on a android project where i am using firebase as back-end and i am building a signup and login form . When ever i sign up the code is working well and . When i try to retrieve it using "signInWithEmailAndPassword i am getting the fallowing error. The email address is badly formatted Firebase`
login Activity
public class login extends AppCompatActivity {
Button create_Account, login_btn;
EditText l_email, l_password;
FirebaseAuth fAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
fAuth = FirebaseAuth.getInstance();
create_Account = findViewById(R.id.l_signup_btn);
create_Account.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(login.this, MainActivity.class));
}
});
l_password = findViewById(R.id.et_lpassword);
l_email = findViewById(R.id.et_lpassword);
login_btn = findViewById(R.id.l_login_btn);
login_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (l_email.getText().toString().isEmpty()) {
l_email.setError("Email is Missing");
return;
}
if (l_password.getText().toString().isEmpty()) {
l_password.setError("Password is Missing");
return;
}
fAuth.signInWithEmailAndPassword(l_email.getText().toString(), l_password.getText().toString()).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
#Override
public void onSuccess(AuthResult authResult) {
startActivity(new Intent(getApplicationContext(), dashboard.class));
finish();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(login.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
}
#Override
protected void onStart() {
super.onStart();
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
startActivity(new Intent(getApplicationContext(), dashboard.class));
finish();
}
}
}
Can you see what mistake you have
l_password = findViewById(R.id.et_lpassword);
l_email = findViewById(R.id.et_lpassword);

Android Firebase Gmail Log out [duplicate]

I have integrated Google authenticate login in my app but after once login if I log out my account still every time app automatically sign in the old user account.
MainAcivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth;
private int RC_SIGN_IN=1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if (account != null){
String personName = account.getDisplayName();
String personGivenName = account.getGivenName();
String personFamilyName = account.getFamilyName();
String personEmail = account.getEmail();
String personId = account.getId();
Uri personPhoto = account.getPhotoUrl();
Intent i=new Intent(MainActivity.this,Welcome.class);
i.putExtra("pn",personName);
i.putExtra("pe",personEmail);
startActivity(i);
}
findViewById(R.id.sign_in_button).setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
// ...
}
}
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
Intent i=new Intent(MainActivity.this,Welcome.class);
startActivity(i);
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("SignInFailed", "signInResult:failed code=" + e.getStatusCode());
Toast.makeText(MainActivity.this,"SignInFailed",Toast.LENGTH_SHORT).show();
}
}
}
Welcome Acivity
public class Welcome extends AppCompatActivity {
TextView textView,textView2;
GoogleSignInClient mGoogleSignInClient;
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
textView=findViewById(R.id.textView);
textView2=findViewById(R.id.textView2);
button=findViewById(R.id.button);
Intent iin= getIntent();
Bundle b = iin.getExtras();
if(b!=null)
{
String j =(String) b.get("pn");
textView.setText(j);
String k =(String) b.get("pe");
textView2.setText(k);
}
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if(account == null){
Intent i=new Intent(Welcome.this,MainActivity.class);
startActivity(i);
}
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
signOut();
}
});
}
private void signOut() {
mGoogleSignInClient.signOut()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Intent i=new Intent(Welcome.this,MainActivity.class);
startActivity(i);
}
});
}
//
}
I have used google docs about sign out but I can't solve my problem. I haven't found any useful questions from already asked by others.
I appreciate any help you folks can offer.
You also need to sign out from GoogleSignInClient and FirebaseAuth current user, something like this:
//sign out of the user and start login activity.
public void signOut() {
signOutBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(getContext(), gso);
mGoogleSignInClient.signOut();
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(getContext(), LoginActivity.class));
}
});
}

When I try to signout from GoogleApiClient I got Error message GoogleApiClient.isConnected() on a null object reference

When I try to sign out from GoogleApiClient I got the following error message
GoogleApiClient.isConnected() on a null object reference
Here is my code:
public static GoogleSignInOptions gso;
public static GoogleApiClient mGoogleApiClient;
//.........
google.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(getContext()).enableAutoManage(getActivity(), new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Toast.makeText(getContext(), "Login failed", Toast.LENGTH_LONG).show();
}
}).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
Intent intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(intent, requestCode);
mGoogleApiClient.connect();
Toast.makeText(getContext(),"User Name "+ acc.getDisplayName()+ "Mail "+acc.getEmail(), Toast.LENGTH_LONG).show();
}
});
and my sign out code
public void signout(){
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(#NonNull Status status) {
Intent intent1 = new Intent(getContext(),LoginActivity.class);
startActivity(intent1);
getActivity().finish();
}
});
And I also tried:
if (UserLogin.mGoogleApiClient.isConnected()) {
UserLogin.mGoogleApiClient.disconnect();
}
Try this...
Define:
public GoogleSignInOptions gso;
public GoogleApiClient mGoogleApiClient;
Initialize in Oncreate method:
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClient.connect();
Now set click listener on signIn button
google.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(intent, requestCode);
Toast.makeText(getContext(),"User Name "+ acc.getDisplayName()+ "Mail "+acc.getEmail(), Toast.LENGTH_LONG).show();
}
});
/////
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(getContext(), "Login failed", Toast.LENGTH_LONG).show();
}
//Sign out
private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
Intent intent1 = new Intent(getContext(),LoginActivity.class);
startActivity(intent1);
getActivity().finish();
}
});
}
Hope this will help you.

Android application takes too much time to start?

I'm finished with android app. Used firebase, admob. Has 31 activities. But when user installs the app for first time, the launch time is approximately 18 seconds which is too high. After first time launching, signup activity is there. But if we relaunch the app then it launches in 2 seconds. Why there is very high launch time? How can I reduce it? Below is my Sign up activity code. Using android studio 2.2
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
private SignInButton mGoogleBtn;
private static final int RC_SIGN_IN=1;
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
private static final String TAG="MAIN_ACTIVITY";
private FirebaseAuth.AuthStateListener mAuthListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth=FirebaseAuth.getInstance();
mAuthListener=new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser()!=null){
startActivity(new Intent(MainActivity.this,Home.class));
}
}
};
mGoogleBtn=(SignInButton)findViewById(R.id.view);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient=new GoogleApiClient.Builder(getApplicationContext())
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Toast.makeText(MainActivity.this,"Login via Google Failed! Press Skip",Toast.LENGTH_LONG).show();
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API,gso)
.build();
mGoogleBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
signIn();
}
});
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed, update UI appropriately
// ...
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
Log.d(TAG, "firebaseAuthWithGoogle:" + account.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed. Press Skip.",
Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this,"Login Successful! Welcome to Unipune Buddy!",Toast.LENGTH_LONG).show();
}
// ...
}
});
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
public void mainscreen(View view){
Intent intent0=new Intent(this,Home.class);
Toast.makeText(MainActivity.this,"Signed in Successfully!",Toast.LENGTH_LONG).show();
startActivity(intent0);
}
}
I too had this issue, what i had done was disabling instant run in the project settings, and rebuilding the project, You can also use Cold start for engaging the user for the first time.

Categories

Resources