4

我有本机应用程序,该应用程序配置为不会破坏设备方向更改的活动。

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

当设备方向发生变化时,触发本机生命周期命令。

/**
 * 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

为什么被屏蔽了?

4

1 回答 1

5

自己想通了原因,

android 本机应用胶水没有用于触发APP_CMD_WINDOW_RESIZED命令的代码。但只有它的定义。

之所以这样,是因为应用胶水代码没有注册本机回调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); 
}

最后,它没有注册的原因是这里描述的一个 android 错误

本机回调的文档在这里

于 2015-09-16T07:26:40.750 回答