4

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 ?

deimus
  • 9,565
  • 12
  • 63
  • 107

1 Answers1

5

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

deimus
  • 9,565
  • 12
  • 63
  • 107
  • I can't prove it, but I suspect that bug report is slightly inaccurate, and that surfaceChanged just isn't being called more than once on app startup. See: https://stackoverflow.com/questions/48137515/android-ndk-handling-orientation-change – user673679 Jan 07 '18 at 20:43