content: package com.allen.reactapp;
  
  import android.app.Activity;
  import android.os.Bundle;
  
  import com.facebook.react.LifecycleState;
  import com.facebook.react.ReactInstanceManager;
  import com.facebook.react.ReactRootView;
  import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
  import com.facebook.react.shell.MainReactPackage;
  
  /**
   * 作者: allen on 16/7/31.
   */
  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")
                  .setJSMainModuleName("index.android")
                  .addPackage(new MainReactPackage())
                  /**
                   * http://stackoverflow.com/questions/37951246/react-native-cannot-find-development-server-integrating-existing-android-app
                   * 调试模式下,建议直接写成 true 吧,我就因为这个错误,调了两天原因
                   */
  //                .setUseDeveloperSupport(BuildConfig.DEBUG)
                  .setUseDeveloperSupport(true)
                  .setInitialLifecycleState(LifecycleState.RESUMED)
                  .build();
          mReactRootView.startReactApplication(mReactInstanceManager, "myreactactivity", null);
  
          setContentView(mReactRootView);
      }
  
      @Override
      public void invokeDefaultOnBackPressed() {
          super.onBackPressed();
      }
      @Override
      protected void onPause() {
          super.onPause();
  
          if (mReactInstanceManager != null) {
              mReactInstanceManager.onHostPause();
          }
      }
  
      @Override
      protected void onResume() {
          super.onResume();
  
          if (mReactInstanceManager != null) {
              mReactInstanceManager.onHostResume(this, this);
          }
      }
  
      @Override
      public void onBackPressed() {
          if (mReactInstanceManager != null) {
              mReactInstanceManager.onBackPressed();
          } else {
              super.onBackPressed();
          }
      }
  
  
  }
  