Facebook login in fragment in android

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 10:41:36

问题


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 possible to add CallbackResult in Fragment's OnActivityResult ??


回答1:


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.




回答2:


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);
        }



回答3:


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) {}


来源:https://stackoverflow.com/questions/34736301/facebook-login-in-fragment-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!