Namespaces

Variants
Actions

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.

Enabling app-closed notifications using Symbian C++

From Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s): S60 3rd Edition
Article
Created: User:Technical writer 1 (27 Sep 2007)
Last edited: hamishwillee (15 Jun 2012)

Overview

Applications may require to do some operations, such as saving data, when being closed without the user's intervention. An application may be closed due to sudden shutdown of the device, either caused by low memory, powering off, or low battery.

Description

This can be handled by checking for the EApaSystemEventShutdown which is sent to all running applications.


Solution

In GUI applications you can check for the event in the HandleSystemEventL method of the UI.

 void CTestAppUi::HandleSystemEventL(const TWsEvent& aEvent)
   {
   switch (*(TApaSystemEvent*)(aEvent.EventData()))
     {
     case EApaSystemEventShutdown:
       // do things here
       break;
     default:
       break;
     }
   // call base class implementation
   CAknAppUi::HandleSystemEventL(aEvent);
   }


This event can also be received in background applications that do not use the application framework, by requesting notifications directly from the window server. In a CActive-derived class, this can be done as follows:

 // During construction
 // Create a session to window server
 // iWs is a class member of type RWsSession
 User::LeaveIfError(iWs.Connect()); 
 
 ...
 
 // listen for WSERV events
 iWs.EventReady(&iStatus);
 SetActive();
 

And in the implementation of CActive::RunL():

 if (iStatus.Int() == KErrNone)
   {
   TWsEvent event;
   iWs.GetEvent(event);
   switch(*(TApaSystemEvent*)(event.EventData()))
     {
     case EApaSystemEventShutdown:
       {
       // do things here
       break;
       }
     default:
       break;
     }
   // issue a new request
   iWs.EventReady(&iStatus);
   SetActive();
   }
 

Also remember to call RWsSession::EventReadyCancel() in CActive::DoCancel(), and RWsSession::Close() in the destructor.

This page was last modified on 15 June 2012, at 01:20.
51 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.

×