简体   繁体   中英

how to call onActivityResult in non Activity class android

I have created Fragment and when click a button get popup like dialog alter view. in that view include google sign in button. when i connect to the firebase and continue the implementation after the startActivityForResult i need to override onActivityResult method. but popup corresponded class extend another Dialog class and can not override onActivityResult method. when going to override it shows method does not override method from its superclass error. how to solve this. and how to implement my firebase login.

thank you. here is my code

public class DialogGoogle extends Dialog  { private Activity activity; @BindView(R.id.btn_google)
LinearLayout btnGoogle; private GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth;
private int RC_SIGN_IN = 1; public DialogGoogle(Activity a, boolean isTab, int width, int height) {
    super(a, R.style.DialogTheme);
    this.activity = a;
    this.isTab = isTab;
    this.windowWidth = width;
    this.windowHeight = height;} 

in onCreate method

// Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();

    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(this.activity.getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this.activity,gso);

After i created some method

public void signInGoogle() {Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);}

in after startActivityForResult() I need to get result and i used onActivityResult() but i cannot override method in that DialogGoogle class. i run usually signInGoogle() method in button click

You start Fragments in a Activity and there you Override the onActivityResult method but first you start your auth like in the documentation:

List<AuthUI.IdpConfig> providers = Arrays.asList(
    new AuthUI.IdpConfig.EmailBuilder().build(),
    new AuthUI.IdpConfig.PhoneBuilder().build(),
    new AuthUI.IdpConfig.GoogleBuilder().build(),
    new AuthUI.IdpConfig.FacebookBuilder().build(),
    new AuthUI.IdpConfig.TwitterBuilder().build());
// Create and launch sign-in intent
startActivityForResult(
    AuthUI.getInstance()
            .createSignInIntentBuilder()
            .setAvailableProviders(providers)
            .build(),
    RC_SIGN_IN);

RC_SIGN_IN is a static field and this is the indicator that you can check if the Activity is finished.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM