Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android/activity: Add Application.ActivityLifecycleCallbacks helpers #2669

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

dbnicholson
Copy link
Contributor

The Application.ActivityLifecycleCallbacks interface is used to register a class that can receive callbacks on Activity lifecycle changes. Add a PythonJavaClass implementing the interface and helper functions to register python callbacks with it. This can be used to perform actions in the python app when the activity changes lifecycle states.

@misl6 misl6 self-assigned this Sep 10, 2022
@misl6
Copy link
Member

misl6 commented Sep 12, 2022

Code looks super good and promising, but not tested yet during runtime, meanwhile can you please rebase so we can see a green run from the CI?

@dbnicholson
Copy link
Contributor Author

Code looks super good and promising, but not tested yet during runtime, meanwhile can you please rebase so we can see a green run from the CI?

Do you want me to exercise it in the test app?

@misl6
Copy link
Member

misl6 commented Sep 12, 2022

Code looks super good and promising, but not tested yet during runtime, meanwhile can you please rebase so we can see a green run from the CI?

Do you want me to exercise it in the test app?

Uh, that would be super nice, but not mandatory.

The rebase was just to include a recent change that will allow the unit tests to run.

@dbnicholson
Copy link
Contributor Author

Do you want me to exercise it in the test app?

Uh, that would be super nice, but not mandatory.

It's fine. I already had something more or less there but I'd punted to work on something else.

@dbnicholson
Copy link
Contributor Author

Well, I'm glad I did because now I found out that it doesn't work on API 31. Trying to figure out why...

The `Application.ActivityLifecycleCallbacks` interface is used to
register a class that can receive callbacks on Activity lifecycle
changes. Add a `PythonJavaClass` implementing the interface and helper
functions to register python callbacks with it. This can be used to
perform actions in the python app when the activity changes lifecycle
states.
@dbnicholson
Copy link
Contributor Author

I rebased and added some callbacks in the test app. It works fine for both sdl2 and webview on API 29 and API 30, but I can't figure out why it doesn't work on API 31. It seems like an Android bug that the callbacks are never sent.

@dbnicholson
Copy link
Contributor Author

I rebased and added some callbacks in the test app. It works fine for both sdl2 and webview on API 29 and API 30, but I can't figure out why it doesn't work on API 31. It seems like an Android bug that the callbacks are never sent.

False alarm. It does work fine on API 31. It just seems they changed the activity lifecycle a bit. Before the activity would be stopped by going to the overview. Now you have to go into a different activity or back to the home screen to go through the pause/stop cycle. Then it will go back through the start/resume cycle when going back to the app.

So, I think this works fine on all the API levels I tried - 29, 30 and 31.

Copy link
Member

@misl6 misl6 left a comment

Choose a reason for hiding this comment

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

LGTM.

Thank you for the tests and well-written docs!
Tested both sdl2 and webview APK on API 31, and worked flawlessly!

@misl6 misl6 merged commit b379a1c into kivy:develop Sep 19, 2022
@dbnicholson dbnicholson deleted the activity-lifecycle branch September 19, 2022 20:14
dbnicholson added a commit to dbnicholson/python-for-android that referenced this pull request Sep 23, 2022
…ivy#2669)

The `Application.ActivityLifecycleCallbacks` interface is used to
register a class that can receive callbacks on Activity lifecycle
changes. Add a `PythonJavaClass` implementing the interface and helper
functions to register python callbacks with it. This can be used to
perform actions in the python app when the activity changes lifecycle
states.

(cherry picked from commit b379a1c)
shyamnathp pushed a commit to shyamnathp/python-for-android that referenced this pull request Feb 17, 2023
…ivy#2669)

The `Application.ActivityLifecycleCallbacks` interface is used to
register a class that can receive callbacks on Activity lifecycle
changes. Add a `PythonJavaClass` implementing the interface and helper
functions to register python callbacks with it. This can be used to
perform actions in the python app when the activity changes lifecycle
states.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants