Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] editing android native code for linking the package #47

Closed
SokWonJeremyKim opened this issue Sep 19, 2018 · 0 comments
Closed

Comments

@SokWonJeremyKim
Copy link

SokWonJeremyKim commented Sep 19, 2018

Hello.

My react native app is integrated with a pre-existing android native application.
So, I've followed the steps explained in this link.

http://facebook.github.io/react-native/docs/integration-with-existing-apps

The problem is that
When I try to link react-native-threads package upon this basis, I don't have a certain argument to feed.
The bridging activity starts like this.

public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
    private ReactRootView mReactRootView;
    private ReactInstanceManager mReactInstanceManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModulePath("index")
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        // The string here (e.g. "MyReactNativeApp") has to match
        // the string in AppRegistry.registerComponent() in index.js
        mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null);

        setContentView(mReactRootView);
    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
}

As explained in the Readme file of this package,

Also note that only the official react native modules are available from your threads (vibration, fetch, etc...). To include additional native modules in your threads, pass them into the RNThreadPackage constructor after the mReactNativeHost like this: new RNThreadPackage(mReactNativeHost, new ExampleNativePackage(), new SQLitePackage())

I tried to feed "mReactNativeHost".

At first, I tried this code

private ReactRootView mReactRootView;
...
mReactNativeHost = ((ReactApplication) getApplication()).getReactNativeHost();
...
new RNThreadPackage(mReactNativeHost, new BlePackage())

However, this gives me the log like this:

android.app.Application cannot be cast to com.facebook.react.ReactApplication

I know this is more about the general knowledge on android.

But I'm trying to run bluetooth communication on another process using this package.

So, please help me if any of you guys had an experience like this.

Thank you.

@SokWonJeremyKim SokWonJeremyKim changed the title [Question} [Question] editing android native code for linking the package Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant