Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Detecting focus change with RGA

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Tested with
Devices(s): Nokia N93, Nokia N95
Platform(s): S60 3rd Edition
Created: stolik (24 Sep 2008)
Last edited: lpvalente (18 Sep 2012)



This code snippet shows how to handle an application's actions while it has lost or gained focus with the RGA API.

Note: In order to use this code, you need to install the Open C plug-in.


To use this snippet you need to inherit your class from IApplicationStateObserver and create an instance of the IApplicationState object and set an observer to you class. Also you'll need to define the FocusGained() or/and FocusLost() functions which will be called by the observer.

This example relies on RGA API ngi and examplefw frameworks.

To run this snippet you need to use the ngi and examplefw frameworks provided with Open C/C++ Plug-ins for S60 3rd Edition. Examplefw sources are located in the "\nokia_plugin\rga\s60rgaex\common\gameexfw\src\" folder after the plug-in has been installed.

MMP file

The following capabilities and libraries are required:

LIBRARY euser.lib
LIBRARY runtime.lib
LIBRARY libc.lib
LIBRARY libm.lib
LIBRARY libpthread.lib

Note: The snippet itself doesn't require any special capabilities, but due to the use of RGA API ngi framework, the resulting application requires SwEvent capability. (See also Open C/C++ DLL.)

Header file

#include <applicationstate.h>    // ngi
using namespace ngi;
class CExampleApplication : public IApplicationStateObserver
* Application gained focus.
* Observer method for the gained focus event.

virtual void FocusGained() NO_THROW;
* Application lost focus.
* Observer method for the lost focus event.

virtual void FocusLost() NO_THROW;
/// Pointer to the application state object.
IApplicationState* mApplicationState;

Source file

#include <errorcodes.h>         // ngi
#include <runtime.h> // ngi
#include <standardtypes.h> // ngi
#include "helper.h" //examplefw
if( mApplicationState )
mApplicationState->SetObserver( NULL );
mApplicationState = NULL;
bool32 CExampleApplication::Initialize()
if( CRuntime::CreateInstance( mApplicationState ) != OK)
return FALSE;
mApplicationState->SetObserver( this );
return TRUE;
// ---------------------------------------------------------
// This method is called when application looses focus.
// ---------------------------------------------------------
void CExampleApplication::FocusLost() NO_THROW
//Do necessary action on losing of focus
// ---------------------------------------------------------
// This method is called when application gets focus.
// ---------------------------------------------------------
void CExampleApplication::FocusGained() NO_THROW
//Do necessary action on gaining of focus


The observer will call FocusGained() or FocusLost() on focus load or gained events.

This page was last modified on 18 September 2012, at 18:09.
21 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.