module nit_activity

Core implementation of app.nit on Android using a custom Java entry point

This module is implemented in 3 languages:

  • The Java code, in acts as the entry point registered to the Android OS. It relays most of the Android callbacks to C. In theory, there may be more than one instance of NitActivity alive at a given time. They hold a reference to the corresponding Nit Activity in the attribute nitActivity.

  • The C code is defined in the top part of this source file. It acts as a glue between Java and Nit by relaying calls between both languages. It keeps a global variables reference to the Java VM and the Nit App.

  • The Nit code defines the Activity class with the callbacks from Android. The callback methods should be redefined by user modules.

The main is invoked when the native library is dynamically linked by the Java virtual machine. For this reason, the main must execute quickly, on the main UI thread at least.




  • bundle: A mapping class of String to various value types used by the
  • dalvik: Java related services specific to Android and its Dalvik VM
  • key_event
  • log: Advanced Android logging services


  • at_boot: Import this module to launch Service at device boot
  • http_request: Android implementation of app:http_request
  • native_ui: Native services from the android.view and android.widget namespaces
  • service: Android service support for app.nit centered around the class Service
  • ui: Views and services to use the Android native user interface
  • ui_test: Test for app.nit's UI services
  • wifi: Simple wrapper of the Android WiFi services


  • android: Android platform support and APIs
    • nit_activity: Core implementation of app.nit on Android using a custom Java entry point
  • core: Nit common library of core classes and methods
    • kernel: Most basic classes and methods.
  • app: app.nit, a framework for portable applications
    • app_base: Base of the app.nit framework, defines App

in android::nit_activity


class Activity

An Android activity

You must implement the callbacks (prefixed with on_) to follow the standard Android life-cycle.

  • native: Native Java activity
  • native=: Native Java activity
  • on_create: Notification from Android, the activity is created
  • on_restart: Notification from Android, the activity has been restarted
  • on_start: Notification from Android, the activity has been started
  • on_resume: Notification from Android, the activity has been resumed
  • on_pause: Notification from Android, the activity has been paused
  • on_stop: Notification from Android, the activity has been stopped
  • on_destroy: Notification from Android, the activity is being destroyed
  • on_restore_instance_state: Notification from Android, the activity is being re-initialized from a save_state
  • on_save_instance_state: Notification from Android, the activity may be stopped, save state
  • on_low_memory: Notification from Android, the system is running low on memory
  • on_window_focus_changed: Notification from Android, the current window of the activity has lost or gained focus
  • on_configuration_changed: Notification from Android, the current device configuration has changed
  • on_back_pressed: The back key has been pressed
  • on_key_down: A key has been pressed
  • on_key_long_press: A key has been long pressed
  • on_key_multiple: Multiple down/up pairs of the same key have occurred in a row
  • on_key_up: A key has been released
  • SELF: Type of this instance, automatically specialized in every class
  • init

from core::kernel


redef class Sys

The main class of the program.

Sys is a singleton class, its only instance is accessible from everywhere with sys.

Because of this, methods that should be accessible from everywhere, like print or exit, are defined in Sys. Moreover, unless there is an ambiguity with self, the receiver of a call to these methods is implicitly sys. Basically it means that the two following instructions are equivalent.

print "Hello World"
sys.print "Hello World"

Methods Implicitly Defined in Sys

Sys is the class where are defined top-level methods, i.e. those defined outside of any class like in a procedural language. Basically it means that

redef class Sys
   fun foo do print "hello"

is equivalent with

fun foo print "hello"

As a corollary, in a top-level method, self (the current receiver) is always sys.

  • jvm: Default Java Virtual Machine to use
  • main: The main method of a program.

from app::app_base




redef abstract class AppComponent

An element of an application that is notified of the application life cycle

Most users of app.nit need only to implement on_create to setup the application.

On mobile devices, the application can be stopped a anytime when another application takes the foreground. Implement the callbacks on_save_state and on_load_state to keep the state of the application between execution, for an illusion of continuous execution.

  • on_start: The application is starting or restarting, it is visible to the user
  • on_destroy: The application is being destroyed