React-native-navigation: [V2][Android] ActivityCallbacks missing

Created on 24 Apr 2018  ·  8Comments  ·  Source: wix/react-native-navigation

Issue Description

I am trying to use RNN V2 alongside react-native-fbsdk, which requires the onActivityResult event.

For V1 the solution was to use the setActivityCallbacks method as explained in the V1 docs and https://github.com/wix/react-native-navigation/issues/373#issuecomment-270015677

With V2 however com.reactnativenavigation.controllers.ActivityCallbacks no longer exists, and I can't find anything which offers the same functionality in the V2 code. I see NavigationActivity now has some onResume() and similar hooks but I don't know if that covers it?

Steps to Reproduce / Code Snippets / Screenshots

Code I attempted to use:

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);

    // Facebook
    setActivityCallbacks(new ActivityCallbacks() {
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
      }
    });

    FacebookSdk.sdkInitialize(getApplicationContext());

    AppEventsLogger.activateApp(this);

    super.getReactGateway().onActivityCreated();
  }

Environment

  • React Native Navigation version: 2.0.2246
  • React Native version: 0.55.2
  • Platform(s): Android
  • Device info: Device, Debug, Android 7.1

Most helpful comment

ActivityCallbacks are no longer needed in v2 as your Activity extends NavigationActivity.

All 8 comments

ActivityCallbacks are no longer needed in v2 as your Activity extends NavigationActivity.

Ah... Had tried that but wasn't working for me, now that I've tried again it does in fact work. Sorry!

@Slessi I have same problem.
Can you share your solotion? Thanks

setActivityCallbacks(new ActivityCallbacks() {
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
      }
    });
// MainActivity.java
package com.your.app;

import android.content.Intent;

import com.reactnativenavigation.NavigationActivity;

public class MainActivity extends NavigationActivity {

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
    }
}

@Slessi Can you share MainActivity and MainApplication as callback for Facebook has to be called as

protected List<ReactPackage> getPackages() {
     return Arrays.<ReactPackage>asList(
      new FBSDKPackage(mCallbackManager)
     );
   }

@rf1804 I haven't touched this since April, refer to previous comment

Can you @Slessi provide MainActivity and MainApplication code or if you can explain a little bit like as you shared the code is of MainActivity but callback manager is required to be included in MainApplication

@rf1804 You need a static method to access to the instance of the callbackManager:

public class MainApplication extends NavigationApplication {

    private static CallbackManager mCallbackManager = CallbackManager.Factory.create();

    protected static CallbackManager getCallbackManager() {
        return mCallbackManager;
    }

Then you can use this code in the MainActivity class: https://github.com/wix/react-native-navigation/issues/3102#issuecomment-421543597

Was this page helpful?
0 / 5 - 0 ratings

Related issues

charlesluo2014 picture charlesluo2014  ·  3Comments

yayanartha picture yayanartha  ·  3Comments

Chipped1 picture Chipped1  ·  3Comments

yedidyak picture yedidyak  ·  3Comments

edcs picture edcs  ·  3Comments