1、主Activity入口在AndroidMainifest.xml中定义
<activity>
android:name="org.cocos2dx.javascript.AppActivity"
...
</activity>
2、Cocos2dxActivity的onCreate()方法
AppActivity继承Cocos2dxActivity,在它的onCreate()方法并没有处理太多东西,而是调用了父类的onCreate()方法。代码如下:
protected void onCreate(final Bundle savedInstanceState) {
Log.d(TAG, "Cocos2dxActivity onCreate: " + this + ", savedInstanceState: " + savedInstanceState);
super.onCreate(savedInstanceState);
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
if (!isTaskRoot()) {
// Android launched another instance of the root activity into an existing task
// so just quietly finish and go away, dropping the user back into the activity
// at the top of the stack (ie: the last state of this task)
finish();
Log.w(TAG, "[Workaround] Ignore the activity started from icon!");
return;
}
this.hideVirtualButton();
CAAgent.enableDebug(false);
Cocos2dxHelper.registerBatteryLevelReceiver(this);
onLoadNativeLibraries();
sContext = this;
this.mHandler = new Cocos2dxHandler(this);
Cocos2dxHelper.init(this);
this.mGLContextAttrs = getGLContextAttrs();
this.init();
if (mVideoHelper == null) {
mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
}
if(mWebViewHelper == null){
mWebViewHelper = new Cocos2dxWebViewHelper(mFrameLayout);
}
if(mEditBoxHelper == null){
mEditBoxHelper = new Cocos2dxEditBoxHelper(mFrameLayout);
}
Window window = this.getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
3、Cocos2dxActivity的init()方法
4、GLSurfaceView和GLSurfaceView.Render
5、c++中实现的nativeInit函数
未完待续。。