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 Lifecycle convergence #7989
Conversation
Replaces previous divergence between Android and Kivy state machines.
Corrects previous behavior where Kivy app stops, but Android does not stop.
Let Kivy app state follow Android state.
It is unclear it "default case" refers to existence of a return statement, or existence of a method.
Executive SummaryOn a mobile device (unlike a desktop) the Kivy Lifecycle is an abstraction of a lifecycle implemented in the OS. The Kivy and OS state machines muct remain synchronized to avoid ambigious states. This PR addresses differences between these state machines on Android, it may be a template for extending these observations to iOS. IssuesOn Android the cases where the Kivy state machine diverges from the Android state machine are:
In this PR we address issues i thru iv. Issues v and vi are not Kivy issues. Discussion and proposed changes
Both Android api calls used in this PR are available on all current p4a supported Android versions.
|
from android import mActivity | ||
mActivity.moveTaskToBack(True) | ||
return True | ||
elif WindowBase.on_keyboard.exit_on_escape: | ||
if key == 27 or all([is_osx, key in [113, 119], modifier == 1024]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just question:
shouldnt we do some key mapper to constants for keys such "27" (android) and 113 like here etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because it is a change that would be mission creep for this PR. This PR uses the existing conventions for the express purpose of being clear about the functional changes.
If this kind of thing is important to you, please submit a PR.
- Explain why you propose the changes.
- Show that the changes are consistent across the Kivy code base.
- Think about 27 which is not ESC on Android, it just looks that way to a user because of this https://github.com/kivy/kivy/blob/master/kivy/core/window/window_sdl2.py#L209-L211
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was NOT asking to make it in this PR :) but just asked question globally, in future [separate PR], whatever :)
But you are maybe right. I was thinking in same way pygame was handling keys, they were mapped like K_BACKSPACE, K_ESCAPE, K_SLASH etc.
I though it might improve readability of code somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I should have been clearer, I get why you would like this.
And, really, you could write that PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Tested on runtime (on API 31) with all the possible combinations ✅
- Code LGTM. (we can do something to avoid some minor DRY violations, but we can target it later) ✅
- Left some minor suggestions 🧐
Thank you!
Regarding:
Case ii Revisited) The case is addressed in this PR, but I really think the 'on_pause return' feature should be removed. The utility is unclear to me (self.stop() exists and is more intuative) and there is an unfortunate side effect. As designed, if a user omits the return statement in on_pause there will be no effect on desktop execution (on_pause is not called) but on mobile the app will correctly dissappear from the screen and the task list. The connection between a simple coding error and the app behavior is not intuative. This PR logs this event, and corrects an ambiguity in the comment/documentation. If there is interest in removing the functionality I can create a PR for this.
I guess we can discuss it on a separate issue, and if we decide to remove that feature, it will need to be deprecated at first, and then removed in 2/3 releases.
''' | ||
if platform == 'android': | ||
from android import mActivity | ||
mActivity.moveTaskToBack(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Maybe we can add a log that warns the developer about the non-availability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored-by: Mirko Galimberti <me@mirkogalimberti.com>
Faced with inertia I'm less enthusiastic! Its really about cleaning up some fuzzy design, not a bug. So not something I'd fight hard for. A quick search finds 3 cases:
I could add a Logger.warning message in the return False case. The return True case is a NOP and of course very common, a warning in that case would generate a storm of confusion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
Let's open an issue to keep it tracked! 😃 |
For anybody reading this in my future, it turns out issue iv) 'service lifetime' has previously been fixed kivy/python-for-android#2401 |
Maintainer merge checklist
Component: xxx
label.api-deprecation
orapi-break
label.release-highlight
label to be highlighted in release notes.versionadded
,versionchanged
as needed.