An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
main.h File Reference

Go to the source code of this file.


int main (int argc, char **argv)
 This should be implemented by the application including this header.
void ProcessAndroidEvents (int maxWait)

Detailed Description

Header for libfplutil_main.

libfplutil_main makes it easy to build traditional C/C++ applications for Android that use an int main() entry point.

Linking this library adds functionality to call a standard C main() from Android's NativeActivity NDK entry point, android_main(). This helps you by by making it very easy to resuse existing programs with a C main() entry point.

For example, this code:

#include "fplutil/main.h"
int main(int argc, char **argv) {
... do stuff ...
return 0;

will launch, "do stuff", and exit the NativeActivity on return from main(). The android_main() is implemented inside this library for you.

If "do stuff" requires nontrivial amounts of time, such as entering a main loop and looping forever, then it is advisable to add a call the ProcessAndroidEvents() function below periodically, which will minimally service events on the native activity looper.

For more information see ndk/sources/android/native_app_glue.

Function Documentation

void ProcessAndroidEvents ( int  maxWait)

Process android events on the main NativeActivity thread ALooper.

This waits for and processes any pending events from the Android SDK being passed into the NDK. The call will block up to maxWait milliseconds for pending Android events.

maxWait0 returns immediately, -1 blocks indefinitely until an event arrives.