You Are Here:

Community: Wiki

This page was last modified on 5 November 2008, at 15:58.

TSS000756 - Enabling notification about application being closed

From Forum Nokia Wiki



ID TSS000756 Creation date September 27, 2007
Platform S60 3rd Edition Devices
Category Base & System Subcategory Application Framework


Keywords (APIs, classes, methods, functions):

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.

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia