Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

[[ LifecycleListeners ]] Allow lcb widgets to register and listen for Android lifecycle events #7339

Merged

Conversation

livecodemichael
Copy link
Contributor

This PR adds handlers to the android-utils module allowing lcb widgets to register for Android lifecycle events (at present these are pause and resume).

Note that we wrap the listener object in LiveCodeActivity.java, allowing for storage in a hash set. A possible alternative would be to use an index based container, with register returning the index of the listener in the container and unregister taking the index of the listener to unregister.

@runrevmark
Copy link
Contributor

runrevmark commented Apr 29, 2020

So I think using an indexed-container would be better. This means we can guarantee an order on calling of OnPause / OnResume. We OnPause in order of addition, and OnResume in reverse order.

There's no need to use/return an index - as the Listeners are objects - unless I'm forgetting something about Java that means we can just use equality?

We can make things super simple - Register appends the given listener object to the list, Unregister removes the most recent matching listener from the list. (By list I mean array which is always dense - so if you delete element 1, all elements above get shuffled back down).

I also think that the code to register/unregister and the list itself should be maintained in the engine view, not the Activity (the Activity is purposely very lightweight).

Finally, I think all registered listeners should pause before the main view does, and resume afterwards - otherwise things they may depend on engine-side might not be in the right state.

(One other thing is that I don't think we need to worry about synchronization, engine/LCB always runs co-operatively so these shouldn't ever be called from two threads at once).

engine/src/java/com/runrev/android/Engine.java Outdated Show resolved Hide resolved
engine/src/java/com/runrev/android/Engine.java Outdated Show resolved Hide resolved
Copy link
Contributor

@runrevmark runrevmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one last thing :)

The commit message is now stale as it refers to Android activity:

[[ LifecycleListeners ]] Add ability to register for lifecycle events on Android

This patch adds methods to the Android `Engine` class to enable subscription to
the `onPause` and `onResume` lifecycle events. Subscription is done by providing
an object implementing the `LifecycleListener` interface. The ability is designed
to be used internally, and to be wrapped by LCB utility methods.

@livecodemichael livecodemichael force-pushed the feature-android_lifecycle_events branch 2 times, most recently from 7466965 to 45aef32 Compare April 30, 2020 07:52
@runrevmark
Copy link
Contributor

@livecode-vulcan review ok 45aef32

@livecode-vulcan
Copy link
Contributor

💙 review by @runrevmark ok 45aef32

livecode-vulcan added a commit that referenced this pull request Apr 30, 2020
…fecycle_events

[[ LifecycleListeners ]] Allow lcb widgets to register and listen for Android lifecycle events

This PR adds handlers to the android-utils module allowing lcb widgets to register for Android lifecycle events (at present these are pause and resume).

Note that we wrap the listener object in LiveCodeActivity.java, allowing for storage in a hash set. A possible alternative would be to use an index based container, with register returning the index of the listener in the container and unregister taking the index of the listener to unregister.
@livecode-vulcan
Copy link
Contributor

😞 test failure 45aef32

  • try-community-armv6-android-sdk26_ndk16r15: success
  • try-community-armv7-android-ndk16r15: success
  • try-community-arm64-android-ndk16r15: success
  • try-community-x86-android-ndk16r15: success
  • try-community-x86_64-android-ndk16r15: success
  • try-community-js-emscripten-sdk1.35: success
  • try-community-universal-ios-iphoneos13.4: pending
  • try-community-universal-ios-iphonesimulator13.4: success
  • try-community-universal-mac-macosx10.9: pending
  • try-community-x86-linux-debian8: pending
  • try-community-x86_64-linux-debian8: pending
  • try-community-x86-win32: pending
  • try-community-x86_64-win32: failure

The patch updates the docs parser to ensure that it correctly
handles handler type definitions. Previously, it was parsing them
as handler definitions, expecting a corresponding end handler and
a docs entry, causing the parser to get confused.
… on Android

This patch adds methods to the Android `Engine` class to enable subscription to
the `onPause` and `onResume` lifecycle events. Subscription is done by providing
an object implementing the `LifecycleListener` interface. The ability is designed
to be used internally, and to be wrapped by LCB utility methods.
… to android utils module

This patch add handlers to the android utils module allowing for
lcb widgets to register to receive lifecycle events.
@runrevmark
Copy link
Contributor

@livecode-vulcan review ok 8cd3d53

@livecode-vulcan
Copy link
Contributor

💙 review by @runrevmark ok 8cd3d53

livecode-vulcan added a commit that referenced this pull request Apr 30, 2020
…fecycle_events

[[ LifecycleListeners ]] Allow lcb widgets to register and listen for Android lifecycle events

This PR adds handlers to the android-utils module allowing lcb widgets to register for Android lifecycle events (at present these are pause and resume).

Note that we wrap the listener object in LiveCodeActivity.java, allowing for storage in a hash set. A possible alternative would be to use an index based container, with register returning the index of the listener in the container and unregister taking the index of the listener to unregister.
@livecode-vulcan
Copy link
Contributor

😎 test success 8cd3d53

  • try-community-armv6-android-sdk26_ndk16r15: success
  • try-community-armv7-android-ndk16r15: success
  • try-community-arm64-android-ndk16r15: success
  • try-community-x86-android-ndk16r15: success
  • try-community-x86_64-android-ndk16r15: success
  • try-community-js-emscripten-sdk1.35: success
  • try-community-universal-ios-iphoneos13.4: success
  • try-community-universal-ios-iphonesimulator13.4: success
  • try-community-universal-mac-macosx10.9: success
  • try-community-x86-linux-debian8: success
  • try-community-x86_64-linux-debian8: success
  • try-community-x86-win32: success
  • try-community-x86_64-win32: success

@runrevmark runrevmark merged commit b527ae8 into livecode:develop Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants