未调用APP_CMD_WINDOW_RESIZED,但调整了本机窗口的大小 [英] APP_CMD_WINDOW_RESIZED is not called but native window is resized

查看:95
本文介绍了未调用APP_CMD_WINDOW_RESIZED,但调整了本机窗口的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

(我知道ANativeWindow_getHeight函数不是在配置更改处理程序中使用以获得窗口大小的最佳主意,我只需要检查窗口是否已调整大小即可.)

(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

为什么它被阻止了?

推荐答案

弄清楚自己的原因,

Android本机应用程序胶水没有用于触发APP_CMD_WINDOW_RESIZED命令的代码.但是只有它的定义.

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

之所以这样做,是因为应用程序粘贴代码未注册本机回调onNativeWindowResized

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

本机回调的文档位于此处

这篇关于未调用APP_CMD_WINDOW_RESIZED,但调整了本机窗口的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆