×
Namespaces

Variants
Actions
Revision as of 10:53, 19 June 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:How to Handle Events while Application is in BackGround in Symbian C++

From Nokia Developer 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}}.

Article Metadata
CompatibilityArticle
Created: dinesh547 (25 Dec 2008)
Last edited: hamishwillee (19 Jun 2012)

Sometimes we need to handle events in our application while our application runs in background.

For e.g:

  • Need to bring your application in foreground by pressing some keys.
  • Doing a specific task like stopping/starting a background running server by pressing keys.
  • Taking a screenshot of your phone desktop by pressing some specific keys, etc.

Here are some code snippets that show how to do this simply(Please note that all code snippets shown here is written in Appui.cpp of the application here).

We need to add some code like this during ConstructL() of our class.

 CEikonEnv::Static()->RootWin().CaptureKey(EKeyYes, 0, 0);

The above code signifies that our application need to capture event of type EkeyYes. We can capture more events by adding the above line for different keys. For more detail on this please refer to the SDK documentation.

Please note that you need to cancel the CaptureKey when your application exits. The code for this is as follows which you should call in your application's destructor.

iCoeEnv->RootWin().CancelCaptureKey(EKeyYes );

Now you need to override the virtual function of CCoeAppui class in your application.

 void HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination);

This function will be called when you press the key that you have set in CEikonEnv::Static()->RootWin().CaptureKey function above. Since this function is called many times when the window server event happens, to avoid calling it unnecessarily just add the following code in your application.

 void HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination)
{
RWsSession& session = CEikonEnv::Static()->WsSession();
TInt WgId = session.GetFocusWindowGroup();
CApaWindowGroupName* Wgn = CApaWindowGroupName::NewL(session, WgId);
TUid forgroundApp = Wgn->AppUid();
//Checking if the current Application is not in forground
//KAppUid == your Application UID defined as const TUid KAppUid = {yourApplicationUid}
if(forgroundApp != KAppUid)
{
//Add you function/Code here for handling
}
}

Now your function will be called when your application is in the background and when you press the EkeyYes.

This page was last modified on 19 June 2012, at 10:53.
46 page views in the last 30 days.
×