Facebook login in fragment in android

I am trying to login to Facebook using a user interface that worked perfectly in the Activity class. The same thing I have to do in the Fragment. but callback is not executed. Can't add CallbackResult to Fragment OnActivityResult?

+13
source share
3 answers

Yes. It is possible that you are using the facebook login in the snippet, the only thing you need to do is call OnActivityResult in your host activity as follows:

@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 the yout snippet.

+22
source

You just need to add this code to your onActivityResult activity.

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

Then your onActivityResult snippet will certainly work.

  @Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { callbackManager.onActivityResult(requestCode, resultCode, data); } 
+26
source

You just need to add one line inside the fragment

 fbLoginButton.setFragment(this); 

You will get control in

 @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {} 
+1
source

Source: https://habr.com/ru/post/1240400/


All Articles