Namespaces
Variants
Actions

Enabling app-closed notifications using Symbian C++

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 04:20.
100 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved