我是原生应用,配置为不会破坏设备方向更改的活动。
<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
为何被阻止?
答案 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