pyjnius icon indicating copy to clipboard operation
pyjnius copied to clipboard

How does Pyjnius use instance methods as static methods?

Open pakal opened this issue 4 years ago • 2 comments

Python-for-android and other packages use these types of statements, but I can't understand how they can work, since they loads CLASSES (ehere PythonActivity), and call normal, non-static METHODS on them.

How can it be possible? These methods use "this" in their implementation, is there a magic lookup of mActivity or mService static instances on these classes to do the work? If so I'd gladly document it.

        python_activity = autoclass('org.kivy.android.PythonActivity')
        python_activity.checkCurrentPermission(permission + "")

pakal avatar Feb 21 '20 20:02 pakal

https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/recipes/android/src/android/activity.py#L4 this one uses mActivity, do you have an exmaple of where we do this call on the class?

tshirtman avatar Feb 21 '20 23:02 tshirtman

Yes there are multiple similar calls in python-for-android, eg. https://github.com/kivy/python-for-android/blob/8740267d82fc3797a56ee355c9e69f4f30b35a84/pythonforandroid/recipes/android/src/android/permissions.py#L577

I tested it in my own app, the method call works whereas there is no instance explicitly involved.

pakal avatar Feb 22 '20 20:02 pakal

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project. Let us know if this comment was made in error, and we'll be happy to reopen the issue.

github-actions[bot] avatar Oct 28 '23 02:10 github-actions[bot]