Facebook login in fragment in android

后端 未结 3 879
闹比i
闹比i 2020-12-28 17:54

I\'m trying to login Facebook using custom interface it worked fine in Activity class. same thing i have to do in Fragment too. but Callback is not executing. is it not poss

相关标签:
3条回答
  • 2020-12-28 18:34

    You just need to add this code in your Activity onActivityResult.

    for (Fragment fragment : getSupportFragmentManager().getFragments()) {
                //System.out.println("@#@");
                fragment.onActivityResult(requestCode, resultCode, data);
            }
    

    Then your fragment onActivityResult will surely gonna work.

       @Override
            public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    
    
                callbackManager.onActivityResult(requestCode, resultCode, data);
            }
    
    0 讨论(0)
  • 2020-12-28 18:34

    You just need to add one line inside fragment

    fbLoginButton.setFragment(this);
    

    You will get the control in

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {}
    
    0 讨论(0)
  • 2020-12-28 18:52

    Yes it's Posssible to implement facebook login in fragment, the only thing you need to do is call OnActivityResult in your host activity like this:

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            Fragment fragment = getFragmentManager().findFragmentById(R.id.your_host_fragment_in_activity);
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    

    and then call onActivityResult again in yout fragment.

    0 讨论(0)
提交回复
热议问题