Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – stepping the event loop


Let's extend the previous example to step our application when events are processed.

  1. Open jni/Types.hpp and define a new type status to represent return codes:

    #ifndef _PACKT_TYPES_HPP_
    #define _PACKT_TYPES_HPP_
    
    #include <cstdlib>
    
    typedef int32_t status;
    
    const status STATUS_OK   = 0;
    const status STATUS_KO   = -1;
    const status STATUS_EXIT = -2;
    
    #endif
  2. Create the jni/ActivityHandler.hpp header and define an "interface" to observe native activity events. Each possible event has its own handler method: onStart(), onResume(), onPause(), onStop(), onDestroy(), and so on. However, we are generally interested in three specific moments in the activity life cycle:

    • onActivate(), invoked when the activity is resumed and its window is available and focused

    • onDeactivate(), invoked when the activity is paused or the display window loses its focus or is destroyed

    • onStep(), invoked when no event has to be processed and computations can take place

      #ifndef _PACKT_ACTIVITYHANDLER_HPP_...