O'Reilly logo

Android NDK Beginner's Guide - Second Edition 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

We are not done yet. Let's continue our example to handle activity events and log them to the LogCat view:

  1. Continue editing jni/EventLoop.cpp. Implement activate() and deactivate().Check both activity states before notifying the listener (to avoid untimely triggering). We consider an activity as activated only if a display window is available:
    ... void EventLoop::activate() { // Enables activity only if a window is available. if ((!mEnabled) && (mApplication->window != NULL)) { mQuit = false; mEnabled = true; if (mActivityHandler.onActivate() != STATUS_OK) { goto ERROR; } } return; ERROR: mQuit = true; deactivate(); ANativeActivity_finish(mApplication->activity); } void EventLoop::deactivate() { if (mEnabled) ...

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