We are developing an indie game for android and would like the user to choose his nickname. We have chosen to use the Native Activity that is provided by the NDK as that seemed
Peter's solution works well. However if you don't want to modify the native_app_glue file: notice that process_input is assigned as a function pointer. In your implementation file, create your own process_input functions as described by Peter:
static void process_input( struct android_app* app, struct android_poll_source* source) {
AInputEvent* event = NULL;
if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
int type = AInputEvent_getType(event);
LOGV("New input event: type=%d\n", AInputEvent_getType(event));
bool skip_predispatch
= AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY
&& AKeyEvent_getKeyCode(event) == AKEYCODE_BACK;
// skip predispatch (all it does is send to the IME)
if (!skip_predispatch && AInputQueue_preDispatchEvent(app->inputQueue, event)) {
return;
}
int32_t handled = 0;
if (app->onInputEvent != NULL) handled = app->onInputEvent(app, event);
AInputQueue_finishEvent(app->inputQueue, event, handled);
} else {
LOGE("Failure reading next input event: %s\n", strerror(errno));
}
}
At the beginning of your android_main function, assign your version of process_input to android_app->inputPollSource.process.
In your event handler make sure you check for the back key (AKEYCODE_BACK) and intercept it to hide your keyboard if visible.
Note that this problem appears to exist in Android 4.1 and 4.2 - solved in 4.3