Merged
Conversation
6ae7ee0 to
9789d35
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
TextInputActionenum representing action button types on soft keyboards. (#216)InputEvent::TextActionevent for handling action button presses from soft keyboards. (#216)ndkandndk-syscrates are now re-exported underandroid_activity::ndkandandroid_activity::ndk_sys(#194)AndroidApp::java_main_looper()gives access to theALooperfor the Java main / UI thread (#198)AndroidApp::run_on_java_main_thread()can be used to run boxed closures on the Java main / UI thread (#232)android_on_createentry point that gets called from theActivity.onCreate()callback beforeandroid_main()is called, allowing for doing some setup work on the Java main / UI thread before theandroid_mainRust code starts running.For example:
MotionEventhistory, providing higher fidelity input data for things like stylus input (native-activity+game-activitybackends). (#218)Changed
ndk-contextis initialized with anApplicationcontext instead of anActivitycontext (#229)GameActivity 4.4.0 Update
Important: This release is no longer compatible with GameActivity 2.0.2
Android Packaging: Your Android application must be packaged with the corresponding androidX, GameActivity 4.x.x library from Google.
This release has been tested with the
androidx.games:games-activity:4.4.0stablerelease, and is backwards
compatible with the 4.0.0 stable release.
If you use Gradle to build your Android application, you can depend on the 4.4.0 release of the GameActivity library via:
Note: there is no guarantee that later 4.x.x releases of GameActivity will be compatible with this release of
android-activity, so please refer to theandroid-activityrelease notes for any future updates regardingGameActivity compatibility.
Initializing
ndk-contextwith an Application Contextndk-contextis a separate, framework-independent crate that provides a way for library crates to access a Java VM pointer and anandroid.content.ContextJNI reference without needing to depend onandroid-activitydirectly.ndk-contextmay be initialized by various framework crates, includingandroid-activity, on behalf of library crates.Historically
android-activityhas initializedndk-contextwith anActivitycontext since that was the simplest choice considering that the entrypoint forandroid-activitycomes from anActivityonCreatecallback.However, in retrospect it was realized that this was a short-sighted mistake when considering that:
ndk-contextonly provides a single, global context reference for the entire application that can't be updatedActivityinstances over its lifetime (and at times could have noActivityinstances at all, e.g. if the app is running a backgroundService)ndk-contextneeds to leak a corresponding global reference to ensure it remains valid to access safely. This is inappropriate for anActivityreference since it can be destroyed and recreated multiple times over the lifetime of the application.A far better choice, that aligns with the global nature of the
ndk-contextAPI is to initialize it with anApplicationcontext which is valid for the entire lifetime of the application.Note: Although the
ndk-contextAPI only promises to provide anandroid.content.Contextand specifically warns that user's should not assume the context is anActivity, there is still some risk that some users ofndk-contextcould be affected by the change made in #229.For example, until recently the
webbrowsercrate (for opening URLs) was assuming it could access anActivitycontext viandk-context. In preparation for making this change,webbrowserwas updated to ensure it is agnostic to the type of context provided byndk-context, see: amodm/webbrowser-rs#111Other notable library crates that support Android (such as
app_dirs2) are expected to be unaffected by this, since they already operate in terms of theandroid.content.ContextAPI, not theActivityAPI._Note:: if some crate really needs an
Activityreference then they should ideally be able to get one via theAndroidApp::activity_as_ptr()API. They may need to add some Android-specific initialization API, similar to how Winit has a dedicated.with_android_app()API. An Android-specific init API that could accept a JNI reference to anActivitycould avoid needing to specifically depend onandroid-activity.Fixed
AndroidApp::asset_manager()returns anAssetManagerthat has a safe'staticlifetime that's not invalidated whenandroid_main()returns (#233)native-activitybackend clears itsANativeActivityptr afteronDestroyandAndroidAppremains safe to access afterandroid_main()returns (#234)AndroidApp::activity_as_ptr()returns a pointer to a global reference that remains valid untilAndroidAppis dropped, instead of theANativeActivity'sclazzpointer which is only guaranteed to be valid untilonDestroyreturns (native-activitybackend) (#234)game-activitybackend clears itsandroid_appptr afteronDestroyandAndroidAppremains safe to access afterandroid_main()returns (#236)AndroidApp::show/hide_soft_input()APIs in thenative-activitybackend (#178)Overall, some effort was made to ensure that
android-activitycan gracefully and safely handle cases where theActivitygets repeatedly created, destroyed and recreated (e.g due to configuration changes). Theoretically it should even be possible to run multipleActivityinstances (although that's not really something thatNativeActivityorGameActivityare designed for).