mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-08 09:12:05 +08:00
This is an early release and there are several things that are known not to work if you're porting your iOS app to Android. See the Known Issues guide on the website. We will work with the community to reach platform parity with iOS.
70 lines
2.0 KiB
Java
70 lines
2.0 KiB
Java
package <%= package %>;
|
|
|
|
import android.app.Activity;
|
|
import android.os.Bundle;
|
|
import android.view.KeyEvent;
|
|
|
|
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;
|
|
import com.facebook.soloader.SoLoader;
|
|
|
|
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
|
|
|
|
private ReactInstanceManager mReactInstanceManager;
|
|
private ReactRootView mReactRootView;
|
|
|
|
@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())
|
|
.setUseDeveloperSupport(BuildConfig.DEBUG)
|
|
.setInitialLifecycleState(LifecycleState.RESUMED)
|
|
.build();
|
|
|
|
mReactRootView.startReactApplication(mReactInstanceManager, "<%= name %>", null);
|
|
|
|
setContentView(mReactRootView);
|
|
}
|
|
|
|
@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
|
|
public void invokeDefaultOnBackPressed() {
|
|
super.onBackPressed();
|
|
}
|
|
|
|
@Override
|
|
protected void onPause() {
|
|
super.onPause();
|
|
|
|
if (mReactInstanceManager != null) {
|
|
mReactInstanceManager.onPause();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onResume() {
|
|
super.onResume();
|
|
|
|
if (mReactInstanceManager != null) {
|
|
mReactInstanceManager.onResume(this);
|
|
}
|
|
}
|
|
}
|