APP_CMD_WINDOW_RESIZED is not called but native window is resized

不打扰是莪最后的温柔 提交于 2019-12-22 10:28:53

问题


I've native app, which is configured to not destroy activity on device orientation change.

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

When the devices orientation changes only following Native life-cycle command is triggered.

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

In the command handler I can see that the window size has been changed with ANativeWindow_getHeight function.

(I know that ANativeWindow_getHeight function is not the best idea to use in config change handler to get the window size, I just only need to check if the window has been resized.)

If the native windows is resized I suppose following native command should be triggered ?

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

Why it has been blocked ?


回答1:


Figured out the reason myself,

The android native app glue does not have a code for firing APP_CMD_WINDOW_RESIZED command. But only has the definition for it.

The reason for that, is because app glue code does not register the native callback 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); 
}

And finally the reason why it does not register for it is an android bug described here

The documentation of native callbacks is here



来源:https://stackoverflow.com/questions/32587572/app-cmd-window-resized-is-not-called-but-native-window-is-resized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!