blip  0.1
NativeActivity Class Referenceabstract

An abstract base class for all "native" (C++) Android activities. More...

#include <NativeActivity.hpp>

Inheritance diagram for NativeActivity:

Public Member Functions

virtual ~NativeActivity ()
 Destructor. More...
 

Protected Member Functions

 NativeActivity (NativeContext context)
 Construct a new NativeActivity. More...
 
void sleep (timespan_ms_t msec)
 
virtual void onCreate (ccxx::ByteBuffer *buffer)
 This method is called when the activity is being created. More...
 
virtual void onStart ()
 This method is called when the activity is being started. More...
 
virtual void onResume ()
 This method is called when the activity is being resumed. More...
 
virtual void onPause ()
 This method is called when the activity is being paused. More...
 
virtual void onStop ()
 This method is called when the activity is being stopped. More...
 
virtual void onDestroy ()
 This method is called when the activity is about to be destroyed. More...
 
virtual void onSaveInstanceState (ccxx::ByteBuffer *buffer)
 Called when the activity should save its instance state. More...
 
virtual void onConfigurationChanged ()
 This method is called when the device configuration has changed. More...
 
void finish ()
 Finish this activity. More...
 
virtual bool onKeyEvent (const KeyEvent &event)
 This method is called when a KeyEvent is received. More...
 
virtual bool onMotionEvent (const MotionEvent &event)
 This method is called when a MotionEvent is received. More...
 
virtual void onSensorEvent (const SensorEvent &event)
 This method is called when a SensorEvent is received. More...
 
virtual void onTimerEvent (const TimerEvent &event)
 This method is called when a TimerEvent has been received. More...
 
virtual void onIdle ()=0
 Idle callback. More...
 
virtual void onWindowFocusChanged (bool hasFocus)
 This method is called when the activity's window gains or loses input focus. More...
 
virtual void onWindowCreated ()
 This method is called when the activity's window has been created. More...
 
virtual void onWindowDestroyed ()
 This method is called when the activity's window is about to be destroyed. More...
 
virtual void onWindowResized ()
 This method is called when the activity's window has changed size. More...
 
virtual void onWindowRedrawNeeded ()
 This method is called when the activity's window needs to be redrawn. More...
 
virtual void onContentRectChanged (const Rectangle &rect)
 This method is called when the rectangle in the activity's window in which content should be placed has changed. More...
 
virtual void onLowMemory ()
 This method is called when the system is running low on memory. More...
 
AssetManagergetAssetManager ()
 Get the asset manager for this activity. More...
 
const DeviceConfigurationgetDeviceConfiguration ()
 Get the current device configuration. More...
 
ccxx::JavaVirtualMachine * getJavaVirtualMachine ()
 Get the Java Virtual Machine for this activity. More...
 
RenderingContextgetRenderingContext ()
 Get the rendering context for this activity. More...
 
SensorManagergetSensorManager ()
 Get the SensorManager for this activity. More...
 
StorageManagergetStorageManager ()
 Get the StorageManager for this activity. More...
 
TimerManagergetTimerManager ()
 Get the timer manager for this activity. More...
 
WindowgetWindow ()
 Get the native Window for this activity. More...
 
const IntentgetIntent ()
 Get the Intent that this activity was launched with. More...
 
IntentnewIntent ()
 Construct a new Intent object. More...
 
void startActivity (Intent *intent)
 Start a new activity with the given intent. More...
 
ccxx::String getInternalDataPath () const
 Get the filesystem path to application-private data in the device's internal storage (e.g., onboard flash memory). More...
 
ccxx::String getExternalDataPath () const
 Get the filesystem path to shared data in the device's external storage (e.g., removable flash media). More...
 
void showSoftInput (bool forced=false)
 Display the soft input method (e.g., a virtual on-screen keyboard). More...
 
void hideSoftInput ()
 Hide the soft input method (e.g., a virtual on-screen keyboard). More...
 

Detailed Description

An abstract base class for all "native" (C++) Android activities.

This class provides a complete framework for implementing native Android applications, including the following facilities:

  • All Android lifecycle callbacks, plus an "idle" callback.
  • Event callbacks for input events, sensor events, and timer events.
  • Access to the Intent that started the activity.
  • Access to an AssetManager for loading the application's assets from its APK
  • Access to the Java Virtual Machine in the form of a higher-level wrapper around the JNI.
  • Access to the SensorManager.
  • Access to the OpenGL ES rendering context.
  • Access to the device configuration, and a callback to notify the application when the configuration changes (e.g., a screen orientation change from landscape to portrait).
  • Access to the StorageManager for mounting and accessing OBB (opaque binary blobs).

Subclasses must provide a constructor which accepts a single argument, the opaque NativeContext, which must be passed directly to the superclass constructor.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~NativeActivity()

~NativeActivity ( )
virtual

Destructor.

◆ NativeActivity()

NativeActivity ( NativeContext  context)
protected

Construct a new NativeActivity.

Parameters
contextThe native context; this is an opaque value which must be passed along by subclasses.

Member Function Documentation

◆ finish()

void finish ( )
protected

Finish this activity.

Notifies the system that this activity has completed and should be terminated.

◆ getAssetManager()

AssetManager * getAssetManager ( )
protected

Get the asset manager for this activity.

◆ getDeviceConfiguration()

const DeviceConfiguration* getDeviceConfiguration ( )
inlineprotected

Get the current device configuration.

◆ getExternalDataPath()

String getExternalDataPath ( ) const
protected

Get the filesystem path to shared data in the device's external storage (e.g., removable flash media).

◆ getIntent()

const Intent& getIntent ( )
inlineprotected

Get the Intent that this activity was launched with.

◆ getInternalDataPath()

String getInternalDataPath ( ) const
protected

Get the filesystem path to application-private data in the device's internal storage (e.g., onboard flash memory).

◆ getJavaVirtualMachine()

ccxx::JavaVirtualMachine* getJavaVirtualMachine ( )
inlineprotected

Get the Java Virtual Machine for this activity.

◆ getRenderingContext()

RenderingContext* getRenderingContext ( )
inlineprotected

Get the rendering context for this activity.

◆ getSensorManager()

SensorManager * getSensorManager ( )
protected

Get the SensorManager for this activity.

The SensorManager is not initialized until the first call to this method.

◆ getStorageManager()

StorageManager * getStorageManager ( )
protected

Get the StorageManager for this activity.

The StorageManager is not initialized until the first call to this method.

◆ getTimerManager()

TimerManager * getTimerManager ( )
protected

Get the timer manager for this activity.

The TimerManager is not initialized until the first call to this method.

◆ getWindow()

Window* getWindow ( )
inlineprotected

Get the native Window for this activity.

◆ hideSoftInput()

void hideSoftInput ( )
protected

Hide the soft input method (e.g., a virtual on-screen keyboard).

◆ newIntent()

Intent * newIntent ( )
protected

Construct a new Intent object.

The caller must take ownership of the returned object. This is intended for use in conjunction with startActivity() to start a new activity.

Exceptions
JavaExceptionIf an error occurs while instantiating the new object.

◆ onConfigurationChanged()

void onConfigurationChanged ( )
protectedvirtual

This method is called when the device configuration has changed.

The new configuration can be obtained by calling getDeviceConfiguration().

The default implementation does nothing.

◆ onContentRectChanged()

void onContentRectChanged ( const Rectangle rect)
protectedvirtual

This method is called when the rectangle in the activity's window in which content should be placed has changed.

The default implementation does nothing.

Parameters
rectThe bounds of the new content rectangle.

◆ onCreate()

void onCreate ( ccxx::ByteBuffer *  buffer)
protectedvirtual

This method is called when the activity is being created.

The default implementation does nothing.

Parameters
bufferA buffer from which the activity may restore its saved instance state.

◆ onDestroy()

void onDestroy ( )
protectedvirtual

This method is called when the activity is about to be destroyed.

The default implementation does nothing.

◆ onIdle()

virtual void onIdle ( )
protectedpure virtual

Idle callback.

This method is called repeatedly as long as there are no events to be processed. The typical native activity will implement its screen update logic here.

◆ onKeyEvent()

bool onKeyEvent ( const KeyEvent event)
protectedvirtual

This method is called when a KeyEvent is received.

The default implementation does nothing and returns false.

Parameters
eventThe event.
Returns
true if the event was consumed, false otherwise.

◆ onLowMemory()

void onLowMemory ( )
protectedvirtual

This method is called when the system is running low on memory.

The default implementation does nothing.

◆ onMotionEvent()

bool onMotionEvent ( const MotionEvent event)
protectedvirtual

This method is called when a MotionEvent is received.

The default implementation does nothing and returns false.

Parameters
eventThe event.
Returns
true if the event was consumed, false otherwise.

◆ onPause()

void onPause ( )
protectedvirtual

This method is called when the activity is being paused.

The default implementation does nothing.

◆ onResume()

void onResume ( )
protectedvirtual

This method is called when the activity is being resumed.

The default implementation does nothing.

◆ onSaveInstanceState()

void onSaveInstanceState ( ccxx::ByteBuffer *  buffer)
protectedvirtual

Called when the activity should save its instance state.

The default implementation does nothing.

Parameters
bufferA buffer into which the activity may store its instance state.

◆ onSensorEvent()

void onSensorEvent ( const SensorEvent event)
protectedvirtual

This method is called when a SensorEvent is received.

In order to receive sensor events, the application must first enable one or more sensors via the SensorManager.

The default implementation does nothing.

Parameters
eventThe event.

◆ onStart()

void onStart ( )
protectedvirtual

This method is called when the activity is being started.

The default implementation does nothing.

◆ onStop()

void onStop ( )
protectedvirtual

This method is called when the activity is being stopped.

The default implementation does nothing.

◆ onTimerEvent()

void onTimerEvent ( const TimerEvent event)
protectedvirtual

This method is called when a TimerEvent has been received.

In order to receive timer events, the application must first register one or more timers via the TimerManager.

The default implementation does nothing.

◆ onWindowCreated()

void onWindowCreated ( )
protectedvirtual

This method is called when the activity's window has been created.

The activity may access the window itself by calling getWindow(), and may obtain a rendering context for the window by calling getRenderingContext().

The default implementation does nothing.

◆ onWindowDestroyed()

void onWindowDestroyed ( )
protectedvirtual

This method is called when the activity's window is about to be destroyed.

The activity should suspend all drawing and avoid any further access to the window or rendering context.

The default implementation does nothing.

◆ onWindowFocusChanged()

void onWindowFocusChanged ( bool  hasFocus)
protectedvirtual

This method is called when the activity's window gains or loses input focus.

The default implementation does nothing.

Parameters
hasFocusIf true, the window has gained input focus; otherwise the window has lost focus.

◆ onWindowRedrawNeeded()

void onWindowRedrawNeeded ( )
protectedvirtual

This method is called when the activity's window needs to be redrawn.

The method should not return until the window has been fully redrawn.

The default implementation does nothing.

◆ onWindowResized()

void onWindowResized ( )
protectedvirtual

This method is called when the activity's window has changed size.

The application should retrieve the new size and adjust its drawing behavior accordingly.

The default implementation does nothing.

◆ showSoftInput()

void showSoftInput ( bool  forced = false)
protected

Display the soft input method (e.g., a virtual on-screen keyboard).

Parameters
forcedIf true, shows IME even if a physical keyboard is open.

◆ sleep()

void sleep ( timespan_ms_t  msec)
protected

◆ startActivity()

void startActivity ( Intent intent)
protected

Start a new activity with the given intent.

After this method has been called, the intent object can be safely deleted.


The documentation for this class was generated from the following files: