Skip to main content
GameDev.net gamedev.net
🔒 Locked

Android Native Activity

Started by noodleBowl Sep 19, 2015 at 12:14 AM 0 replies 2.1k views
Original Post
noodleBowl
noodleBowl
I'm currently looking into the Native Activity example that comes with the Android NDK and do I have some questions....

I'm looking to start out small, just printing a string when the activity lifecycle changes.
EG onCreate -> onState-> onPause- -> etc. But I kind of don't understand one thing

Maybe my C/C++ skills faded away pretty hard, but how are you supposed to "override" the onXXXX methods located in the android_native_app_glue.c?

For example in java I would extend the Activity class and just do
public void onPause()
{
      System.out.println("Activity was paused");
}
Maybe I'm thinking about this all wrong and I'm actually supposed to use the native_activity.h and create my own "glue" file.


Also does anyone have some solid tutorials on this topic? Ones that are little be more detailed then the samples that are include with the NDK.
Ones that take baby steps and explain what is actually going on
Saleh.r
Saleh.r

Well,you are not supposed to do things that way.

Android entry function has a struct parameter.you can do everything with that , from creating asset manager to listening to activity events and even more.

don't forget to put the app_dummy() on the first line of your entry function.It is needed is the andoid application not android libraries.if you forget put this function you will get strange errors.There is a property in the android_app struct ,onAppCmd that , this is a function that you specify and will call everytime that something happen to your activity such as pause or resume or whatever.

void handle_cmd(struct android_app* app, int32_t cmd){

switch(cmd){

case case APP_CMD_PAUSE:

printf("Activity was paused");

}

}

Android event managing is very similiar with windows.you have an struct , you pass it to a function and you event manager function will call everytime an event occur.and there is appState in the app_struct that you can check for current event in you app loop.

sorry for bad english.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.