rust-mobile / android-activity

Glue for building Rust applications on Android with NativeActivity or GameActivity
251 stars 49 forks source link

How to get Android Native_Window when i use native_activity branch? #69

Closed sry948749099 closed 1 year ago

sry948749099 commented 1 year ago

Hi

I see AndroidApp struct is different between game_activity and native_activity, In game_activity, used ffi::android_app, so we could get native_window form android_app in android_native_app_glue.h. But in native_activity, only used ndk_sys::ANativeActivity there do not have the attribute of native_window, so we could not get native_window for android to render in surface. How can i solve this problem?

Thanks!

MarijnS95 commented 1 year ago

NativeWindow is available directly on AndroidApp via fn native_window(): https://docs.rs/android-activity/latest/android_activity/struct.AndroidApp.html#method.native_window

This getter is implemented for both native-activity and game-activity:

https://github.com/rust-mobile/android-activity/blob/36ddfaa9cea7af9377aa43e0db6cc56e80ccc234/android-activity/src/native_activity/mod.rs#L151-L153

https://github.com/rust-mobile/android-activity/blob/36ddfaa9cea7af9377aa43e0db6cc56e80ccc234/android-activity/src/game_activity/mod.rs#L169-L171