0

我有一个 react-native 应用程序,如果它从 ODK Collect 打开,它就会崩溃。如果从其图标打开,它会打开并完美运行。

错误是In order to use RNScreens components your app's activity need to extend ReactFragmentActivity or ReactCompatActivity

两者都已弃用。我正在使用 react-native-screens ^3.8.0。我尝试了各种建议的解决方案,但我哪儿也不去。

显现:

<activity android:name=".DActivity" android:excludeFromRecents="true" android:noHistory="true">
            <intent-filter>
                <action android:name="com.d.odk"/>

                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

DActivity.java:

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import com.babisoft.ReactNativeLocalization.ReactNativeLocalizationPackage;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.ReactRootView;
import com.facebook.react.shell.MainReactPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
import com.oblador.keychain.KeychainPackage;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import java.util.logging.Logger;
import com.swmansion.reanimated.ReanimatedPackage;
import com.swmansion.rnscreens.RNScreensPackage;
import com.th3rdwave.safeareacontext.SafeAreaContextPackage;


public class DActivity extends Activity implements DefaultHardwareBackBtnHandler {

  private ReactInstanceManager mReactInstanceManager;
  private ReactRootView mReactRootView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); //tried null as well
    mReactRootView = new ReactRootView(this);

    Bundle initialProps = new Bundle();
    initialProps.putString("AppCaller", "Denes");

    mReactInstanceManager = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setCurrentActivity(this)
            .setBundleAssetName("index.android.bundle")
            .setJSMainModulePath("index")
            .addPackage(new MainReactPackage())
            .addPackage(new KeychainPackage())
            .addPackage(new AsyncStoragePackage())
            .addPackage(new ReactNativeConfigPackage())
            .addPackage(new ReactNativeLocalizationPackage())
            .addPackage(new ReanimatedPackage())
            .addPackage(new RNScreensPackage())
            .addPackage(new SafeAreaContextPackage())
            .addPackage(new RNGestureHandlerPackage())
            .setUseDeveloperSupport(BuildConfig.DEBUG)
            .setInitialLifecycleState(LifecycleState.RESUMED)
            .build();
            mReactRootView.startReactApplication(mReactInstanceManager, "app", initialProps);
            setContentView(mReactRootView);
  }


  @Override
  public void onBackPressed() {
    if (mReactInstanceManager != null) {
      mReactInstanceManager.onBackPressed();
    } else {
      super.onBackPressed();
    }
  }

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

  @Override
  protected void onPause() {
    super.onPause();

    if (mReactInstanceManager != null) {
      mReactInstanceManager.onHostPause(this);
    }
  }

  @Override
  protected void onResume() {
    super.onResume();

    if (mReactInstanceManager != null) {
      mReactInstanceManager.onHostResume(this, this);
    }
  }

  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
      mReactInstanceManager.showDevOptionsDialog();
      return true;
    }
    return super.onKeyUp(keyCode, event);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (mReactInstanceManager != null) {
      mReactInstanceManager.onHostDestroy(this);
    }
    if (mReactRootView != null) {
      mReactRootView.unmountReactApplication();
    }
  }



}
4

0 回答 0