android NativeActivity going into onPause when home key is pressed and app is relaunched


On pressing the home button in the android phone, the nativeactivity goes into onStop state.

When the app is relaunched, the nativeactivity starts back from onStart state. Basically the nativeactivity is not going to the onDestroy state and thus onCreate is not called during relaunch.

The problem I am facing is that after the relaunch there is no rendering happening. The RenderScene() function call is not happening. There is no crash and all the log seems to show that resources are de-inited and re-allocated during this process.

My NativeActivity is having the following values set similar to the examples. But changing there has no effect on this bug.




during onStart() of nativeActivity launches a GUIActivity which runs on top and is transparent which means it does not let NativeActivity to go into onPause state.

The only inference (also seen from the log) I can gain is that the NativeActivity is going into onPause state after the relaunch. I am not sure why its going there.

Since I can’t post the log, I am emailing the log file if its of any help. In the log AppInterface==NativeActivity

Please let me know if you identify the reason for the onPause state. Is it possible the EGL context is lost ?

Do you know if I can maually (from code ofcourse) bring the NativeActivity out of the pause state ?


What you describe here is the expected behaviour of an Android activity:

Quoting the website above:

When the user leaves a task by pressing the Home button, the current activity is stopped and its task goes into the background. The system retains the state of every activity in the task. If the user later resumes the task by selecting the launcher icon that began the task, the task comes to the foreground and resumes the activity at the top of the stack.

Having said that, you are right, seems that our PVRShell is not really following this behaviour.

In order to reflect a better Android native lifecycle the commands should be treatead differently. In the file /path/to/SDK/Shell/OS/Android/PVRShellOS.cpp you can see the native_app_glue.

We are doing the OnCreate/OnDestroy work inside the OnStart/OnStop events and that is wrong. I will fix it for the 3.3 release.

Let me suggest you some changes that should fix that:

In android_main():

// Setup our android state

state->userData = &init;

state->onAppCmd = handle_cmd;

state->onInputEvent = handle_input;

init.m_pAndroidState = state;

g_AssetManager = state->activity->assetManager;




__android_log_print(ANDROID_LOG_INFO, “PVRShell”, “Error: Failed to initialise”);




// Call init app

init.m_eState = ePVRShellInitApp;

init.m_bError = !(init.Run() && init.m_eState == ePVRShellInitInstance);


// Handle our events until we have a valid window or destroy has been requested

int ident;

int events;

struct android_poll_source* source;

Also, in handle_cmd() we need to change the OnStart/OnStop and add an OnDestroy:


init->m_bRendering = true;



init->m_bRendering = false;





That should give you the expected lifcycle :slight_smile:



i was talking about this prob since last year

Hi Guillem,

Thanks very much for giving the proper correction !! :slight_smile: That helped me to identify how to get the desired behavior.

For my case I had to keep init->m_bRendering = true for even APP_CMD_PAUSE state also as the NativeActivity lanches a top layer GUIActivity and goes into PAUSE state.