Skip to content

Kivy Technical FAQ

xloem edited this page Dec 15, 2020 · 6 revisions

Kivy Technical FAQ

A place to document miscellaneous Kivy programming tips, tricks, hacks, etc.

KVLANG FAQ

Kivy Python FAQ

Android FAQ

  • How do I access Bluetooth on Android?

You have to use pyjnius, java, or c for now. Some work for BLE at https://github.com/xloem/kivy-gattlib .

  • How do I make a background service?

This is documented at https://github.com/kivy/python-for-android/blob/develop/doc/source/services.rst . Some information regarding pinning services to prevent closure at Android-Background-Services

  • When making a recipe, how do I get java files into the apk?

Your recipe should copy any .java or .class files to self.ctx.javaclass_dir in the postbuild_arch(self, arch) method. This folder will be included in the java classpath. See the pyjnius recipe for an example.

Miscellany

  • When do I make a property a Kivy class-level property, and when should I not?

Recall from the Kivy Properties documentation that the services provided by making something a Kivy Property are:

  • Value Checking / Validation: When you assign a new value to a property, the value is checked against validation constraints. For example, validation for an OptionProperty will make sure that the value is in a predefined list of possibilities. Validation for a NumericProperty will check that your value is a numeric type. This prevents many errors early on.
  • Observer Pattern: You can specify what should happen when a property’s value changes. You can bind your own function as a callback to changes of a Property. If, for example, you want a piece of code to be called when a widget’s pos property changes, you can bind a function to it.
  • Better Memory Management: The same instance of a property is shared across multiple widget instances.

Thus, if you think you will want to use any of those services in conjunction with an attribute, you should probably default to making that attribute a Kivy property. (Occasionally there may be a performance penalty in doing so, but generally speaking, it is advisable to err on the side of using what the Kivy devs have provided, and then later re-factor if such a performance hit becomes noticeable and detrimental. Just remember to avoid using Kivy "keywords," which vary somewhat from class to class, when re-factoring, lest you over-ride something unintentionally.)

Clone this wiki locally