I added Facebook and Google sign in in my app using:
private LoginButton facebook; //package com.facebook.login.widget;
private SignInButton googleSignIn; //package com.google.android.gms.common;
Both buttons work, I would like to prevent the users from clicking the buttons multiple times (every time it's being clicked another request is being sent):
Both cases are handled in the Google and Facebook API as follows:
In the Google sign in, there is a list of Google accounts of the device and once pressed I can not catch that event to disable the button once the user chose his account
In the Facebook sign in, it is handled by a callback registered in the Facebook package (which I don't access to) and I also can not disable the button once clicked.
Edit: Facebook code:
private void ActivateFacebook() {
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
facebook = (LoginButton) rootView.findViewById(R.id.fb);
((LoginButton) facebook).setReadPermissions("email");
((LoginButton) facebook).setFragment(this);
((LoginButton) facebook).registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
onFacebookLogin(loginResult);
}
@Override
public void onCancel() {}
@Override
public void onError(FacebookException error) {
Log.d(TAG, error.getMessage());
}
});
}
What is the best practice in achieving this? Thanks!
If you're starting an intent for the result, you can wrap the call in a conditional block, such as:
boolean requestSent = false;
if(!requestSent) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 101 );
requestSent = true;
} else {
//show a message
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.