Auto resizing in Cocos2dx

I have to include admob adview in my game on Android platform using LinearLayout. I find that when including the Adview below the OpenGL view, I didn’t know the height of the AdView and we got that when the ad was received. The problem here is I didn’t know how to resize the OpenGL view after receive the Ads. After trying and trying, I have below solution work for auto resizing problem:

I add follow method in class Cocos2dxRenderer

private static native void nativeResize(final int pWidth, final int pHeight);

then, update the onSurfaceChanged method in this class like this:

@Override
public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) {
    Cocos2dxRenderer.nativeResize(pWidth, pHeight);
}

And implement the nativeResize method in file main.cpp like this:

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeResize(JNIEnv* env,
        jobject thiz, jint w, jint h) {
    LOGD("On Surface resize. %d, %d", w, h);

    CCEGLView *view = CCEGLView::sharedOpenGLView();
    view->setFrameSize(w, h);
    CCApplication::sharedApplication()->run();
}

My question is whether my approach is stable or not? Is there any better way? Thank in advance. :smiley: