O'Reilly logo

Android NDK Beginner's Guide by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – handling activity events

Let's improve the code created in the previous part:

  1. Open Types.hpp and define a new type status to represent return codes:
    #ifndef _PACKT_TYPES_HPP_
    #define _PACKT_TYPES_HPP_
    
    #include <stdint.h>
    
    typedef int32_t status;
    
    const status STATUS_OK   = 0;
    const status STATUS_KO   = -1;
    const status STATUS_EXIT = -2;
    #endif
  2. Create ActivityHandler.hpp in jni directory. This header defines 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 lifecycle:
    • onActivate(): This method is invoked when activity is resumed and its window is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required