Android#

The Android backend uses Material3 widgets.

The native APIs are accessed using Chaquopy.

Activities and Intents#

On Android, some interactions are managed using Activities, which are started using Intents.

Android’s implementation of the toga.App class includes the method start_activity(), which can be used to start an activity.

toga_android.App.start_activity(self, activity, *options, on_complete=None)#

Start a native Android activity.

Parameters:
  • activity – The android.content.Intent instance to start

  • options – Any additional arguments to pass to the native android.app.Activity.startActivityForResult() call.

  • on_complete – A callback to invoke when the activity completes. The callback will be invoked with 2 arguments: the result code, and the result data.

To use this method, instantiate an instance of android.content.Intent; optionally, provide additional arguments, and a callback that will be invoked when the activity completes. For example, to dial a phone number with the Intent.ACTION_DIAL intent:

from android.content import Intent
from android.net import Uri

intent = new Intent(Intent.ACTION_DIAL)
intent.setData(Uri.parse("tel:0123456789"))

def number_dialed(result, data):
    # result is the status code (e.g., Activity.RESULT_OK)
    # data is the value returned by the activity.
    ...

# Assuming your toga.App app instance is called `app`
app._impl.start_activity(intent, on_complete=number_dialed)