------前提是继承普通的Activity------
升级之后老是报
Unable to add window -- token null is not valid; is your activity running?
升级后的package.json:
{
"name": "RNTest01",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"ajv": "^6.0.0",
"android": "0.0.8",
"eslint": "^4.0.0",
"platform": "^1.3.5",
"react": "^16.3.1",
"react-native": "^0.55.3",
"react-native-fetch-blob": "^0.10.8",
"react-native-filesystem": "^0.1.0",
"react-native-image-crop-picker": "^0.20.1",
"react-native-image-zoom-viewer": "^2.1.3",
"react-native-popupwindow": "^0.3.0",
"react-native-progress": "^3.4.0",
"react-native-scrollable-tab-view": "^0.6.5",
"react-native-storage": "^0.2.2",
"react-native-swipe-list-view": "^1.1.1",
"react-navigation": "^1.5.11"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "16.0.0-alpha.6"
},
"jest": {
"preset": "react-native"
},
"optionalDependencies": {}
}
修改后的Activity
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ReactRootView mReactRootView = new ReactRootView(this);
// “AppRegistry.registerComponent()”的第一个参数
mReactRootView.startReactApplication(getReactInstanceManager(), "RNTest01", null);
setContentView(mReactRootView);
}
@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
}
@Override
protected void onResume() {
super.onResume();
if (getReactInstanceManager() != null) {
getReactInstanceManager().onHostResume(this, this);
}
}
@Override
protected void onPause() {
super.onPause();
if (getReactInstanceManager() != null) {
getReactInstanceManager().onHostPause(this);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (getReactInstanceManager() != null) {
getReactInstanceManager().onHostDestroy(this);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (getReactInstanceManager() != null) {
getReactInstanceManager().onActivityResult(this, requestCode, resultCode, data);
}
}
@Override
public void onBackPressed() {
if (getReactInstanceManager() != null) {
getReactInstanceManager().onBackPressed();
} else {
super.onBackPressed();
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && getReactInstanceManager() != null) {
getReactInstanceManager().showDevOptionsDialog();
return true;
}
return super.onKeyUp(keyCode, event);
}
protected ReactNativeHost getReactNativeHost() {
return ((ReactApplication) getApplication()).getReactNativeHost();
}
public ReactInstanceManager getReactInstanceManager() {
return getReactNativeHost().getReactInstanceManager();
}
}
修改后的Application
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage()
);
}
/** Assets */
@Nullable
@Override
protected String getBundleAssetName() {
return super.getBundleAssetName();
}
/** SD */
@Nullable
@Override
protected String getJSBundleFile() {
return super.getJSBundleFile();
}
/** JS_Server */
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}