未调用APP_CMD_WINDOW_RESIZED,但调整了本机窗口的大小

时间:2015-09-15 13:37:32

标签: android android-ndk native-activity

我是原生应用,配置为不会破坏设备方向更改的活动。

<activity android:name="android.app.NativeActivity"
    ...
    android:configChanges="orientation|screenSize"
    ...
    >

当触发Native life-cycle命令后,设备方向改变

/**
 * Command from main thread: the current device configuration has changed.
 */
APP_CMD_CONFIG_CHANGED

在命令处理程序中,我可以看到窗口大小已使用ANativeWindow_getHeight函数更改。

(我知道ANativeWindow_getHeight函数不是在配置更改处理程序中使用来获取窗口大小的最佳选择,我只需要检查窗口是否已调整大小。)

如果调整本机窗口大小,我想应该触发以下本机命令?

/**
 * Command from main thread: the current ANativeWindow has been resized.
 * Please redraw with its new size.
 */
APP_CMD_WINDOW_RESIZED

为何被阻止?

1 个答案:

答案 0 :(得分:4)

自己弄清楚原因,

android native app glue没有用于触发APP_CMD_WINDOW_RESIZED命令的代码。但只有它的定义。

原因是因为app glue code没有注册本机回调onNativeWindowResized

void ANativeActivity_onCreate(ANativeActivity* activity, 
                             void* savedState, size_t savedStateSize) {
    LOGV("Creating: %p\n", activity);
    activity->callbacks->onDestroy = onDestroy;
    activity->callbacks->onStart = onStart;
    activity->callbacks->onResume = onResume;
    activity->callbacks->onSaveInstanceState = onSaveInstanceState;
    activity->callbacks->onPause = onPause;
    activity->callbacks->onStop = onStop;
    activity->callbacks->onConfigurationChanged = onConfigurationChanged;
    activity->callbacks->onLowMemory = onLowMemory;
    activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
    activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
    activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
    activity->callbacks->onInputQueueCreated = onInputQueueCreated;
    activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
    activity->instance = android_app_create(activity, savedState, savedStateSize); 
}

最后,它没有注册它的原因是一个描述here

的机器人错误

原生回调的文档是here