在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  Android/ 在原生android app里用startActivity方式打開react n

在原生android app里用startActivity方式打開react native寫的頁面沒有生效

目前有一個老的android項目是用原生java語言寫的,現(xiàn)在想集成react native,打算新的需求用js開發(fā)。

目前已經(jīng)成功在項目里集成了react native,并且如果app啟動時的activity是這個react native對應(yīng)的activity的話,能正常啟動并且展示正常。

但是如果在老的項目內(nèi)加一個button,用startActivity的方式跳轉(zhuǎn)到react native寫的activity的話,沒有報錯,頁面是空的,沒有任何效果。

老的android項目內(nèi)增加的button,跳轉(zhuǎn)到新的用react native寫的代碼:
mBtnForward.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.i(TAG, "打開新的頁面");
        Intent intent = new Intent();
        intent.setClass(StartActivity.this, BaseReactActivity.class);
        startActivity(intent);
    }
});
AndroidManifest.xml配置
<activity
    android:name=".activity.BaseReactActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
</activity>
BaseReactActivity的代碼
package com.sitech.ac.activity;

import com.facebook.react.ReactActivity;

public class BaseReactActivity extends ReactActivity {

    @Override
    protected String getMainComponentName() {
        return "HelloWorld";
    }

}
App.js
import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
      <Button
        title="你好"
        color="red"
        accessibilityLabel="Learn more about this purple button"
      />
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          測試
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'yellow',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
回答
編輯回答
骨殘心

剛才又重新試了一下,應(yīng)該是bundle服務(wù)器自動掉了,沒有加載到j(luò)s導致的。但是為什么bundle會自動掉了呢? windows平臺。

2017年6月25日 08:21