无法添加android片段来响应本机项目。活动中没有任何布局文件可添加片段

时间:2019-01-21 11:23:12

标签: react-native-android

我有一个正在运行的React Native项目,我只想在Android端添加一个片段。我还在RN项目中建立了一个Android项目。在Android项目中,只有一个Activity,没有 setView(...)这样的操作,也没有布局

公共类MainActivity扩展了ReactActivity {

private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";

private ReactInstanceManager mReactInstanceManager;
private ReactRootView mReactRootView;

private CommentsFragment commentsFragment;
private FragmentTransaction fTrans;
private FragmentManager fragmentManager;

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

    commentsFragment = new CommentsFragment();
    fragmentManager = getFragmentManager();

    mReactInstanceManager = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setBundleAssetName("index.android.bundle")
            .setJSMainModulePath("index.android")
            .addPackage(new MainReactPackage())
            .addPackage(...)
            ...
            .setUseDeveloperSupport(BuildConfig.DEBUG)
            .setInitialLifecycleState(LifecycleState.RESUMED)
            .build();

    Intent intent = getIntent();
    if (intent != null) {
        Uri uri = intent.getData();

        if (uri != null) {
            MainApplication application = (MainApplication) getApplication();
            Tracker tracker = application.getDefaultTracker();
            tracker.enableAdvertisingIdCollection(true);
            tracker.setScreenName("Android app launch by url");
            tracker.send(new HitBuilders.ScreenViewBuilder()
                    .setCampaignParamsFromUrl(uri.toString())
                    .build());
        }
    }
}

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() { return "...";}

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

}

我想在Android应用中显示一个弹出片段。

0 个答案:

没有答案