Fuji/Source/Drivers/Android/android_native_app_glue.cpp
static struct android_app* android_app_create(ANativeActivity* activity,
        void* savedState, size_t savedStateSize) {
    struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app));
    memset(android_app, 0, sizeof(struct android_app));
    android_app->activity = activity;

    pthread_mutex_init(&android_app->mutex, NULL);
    pthread_cond_init(&android_app->cond, NULL);

    if (savedState != NULL) {
        android_app->savedState = malloc(savedStateSize);
        android_app->savedStateSize = savedStateSize;
        memcpy(android_app->savedState, savedState, savedStateSize);
    }

    int msgpipe[2];
    if (pipe(msgpipe)) {
        LOGI("could not create pipe: %s", strerror(errno));
    }
    android_app->msgread = msgpipe[0];
    android_app->msgwrite = msgpipe[1];

    pthread_attr_t attr; 
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    pthread_create(&android_app->thread, &attr, android_app_entry, android_app);

    // Wait for thread to start.
    pthread_mutex_lock(&android_app->mutex);
    while (!android_app->running) {
        pthread_cond_wait(&android_app->cond, &android_app->mutex);
    }
    pthread_mutex_unlock(&android_app->mutex);

    return android_app;
}
// --------------------------------------------------------------------
// Native activity interaction (called from main thread)
// --------------------------------------------------------------------
Native activity interaction (called from main thread)
Native activity interaction ( called from main thread )
static struct android_app* android_app_create(ANativeActivity* activity,
        void* savedState, size_t savedStateSize) {
    struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app));
    memset(android_app, 0, sizeof(struct android_app));
    android_app->activity = activity;
    pthread_mutex_init(&android_app->mutex, NULL);
    pthread_cond_init(&android_app->cond, NULL);
    if (savedState != NULL) {
        android_app->savedState = malloc(savedStateSize);
        android_app->savedStateSize = savedStateSize;
        memcpy(android_app->savedState, savedState, savedStateSize);
    }
    int msgpipe[2];
    if (pipe(msgpipe)) {
        LOGI("could not create pipe: %s", strerror(errno));
    }
    android_app->msgread = msgpipe[0];
    android_app->msgwrite = msgpipe[1];
    pthread_attr_t attr; 
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    pthread_create(&android_app->thread, &attr, android_app_entry, android_app);
    pthread_mutex_lock(&android_app->mutex);
    while (!android_app->running) {
        pthread_cond_wait(&android_app->cond, &android_app->mutex);
    }
    pthread_mutex_unlock(&android_app->mutex);
    return android_app;
}
static struct android_app * android_app_create ( ANativeActivity * activity , void * savedState , size_t savedStateSize ) { struct android_app * android_app = ( struct android_app * ) malloc ( sizeof ( struct android_app ) ) ; memset ( android_app , 0 , sizeof ( struct android_app ) ) ; android_app -> activity = activity ; pthread_mutex_init ( & android_app -> mutex , NULL ) ; pthread_cond_init ( & android_app -> cond , NULL ) ; if ( savedState != NULL ) { android_app -> savedState = malloc ( savedStateSize ) ; android_app -> savedStateSize = savedStateSize ; memcpy ( android_app -> savedState , savedState , savedStateSize ) ; } int msgpipe [ 2 ] ; if ( pipe ( msgpipe ) ) { LOGI ( " " , strerror ( errno ) ) ; } android_app -> msgread = msgpipe [ 0 ] ; android_app -> msgwrite = msgpipe [ 1 ] ; pthread_attr_t attr ; pthread_attr_init ( & attr ) ; pthread_attr_setdetachstate ( & attr , PTHREAD_CREATE_DETACHED ) ; pthread_create ( & android_app -> thread , & attr , android_app_entry , android_app ) ; pthread_mutex_lock ( & android_app -> mutex ) ; while ( ! android_app -> running ) { pthread_cond_wait ( & android_app -> cond , & android_app -> mutex ) ; } pthread_mutex_unlock ( & android_app -> mutex ) ; return android_app ; }
Native activity interaction (called from main thread)
Native activity interaction ( called from main thread )
// Wait for thread to start.