| ID | TSS000756 | Creation date | September 27, 2007 |
| Platform | S60 3rd Edition | Devices | |
| Category | Base & System | Subcategory | Application Framework |
| Keywords (APIs, classes, methods, functions): |
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.
This can be handled by checking for the EApaSystemEventShutdown which is sent to all running applications.
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.