Environmental Change Notifier

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: manchana.bhasker@wipro.com (28 May 2008)
Last edited: hamishwillee (23 Jul 2012)
Reviewer Approved    Thumbs up icon sm.jpg



This class is used to handle the Environment change notifications. It is an active object and can be used to receive environment change events.

Use Case

These APIs are used to get notifications when there is a change in system events like system locale, system time has passed midnight, thread in the system dies, system time has changed, status of the power supply, free memory level has crossed a specified threshold value, memory allocation failed due to insufficient free memory.

Header Files

#include <BACNTF.H>
#include <E32CONST.H>

Libraries in MMP

LIBRARY bafl.lib

Code Snippet

The following code is used to instantiate an object of CEnvironmentChangeNotifier class:

CEnvironmentChangeNotifier*   iNoMemNotifier;
iNoMemNotifier = CEnvironmentChangeNotifier::NewL(
CActive::EPriorityStandard, TCallBack( NoMemCallBack, this ) );

The callback function will be hit whenever there is a change in Environment where we can handle that change.

The following is the code snippet for the call back function:

TInt CHelloWorldBasicAppUi::NoMemCallBack( TAny* aPtr )
reinterpret_cast < CHelloWorldBasicAppUi* >( aPtr )->HandleEnvironmentChange();
return KErrNone;
void CHelloWorldBasicAppUi::HandleEnvironmentChange()
TInt envChange = iNoMemNotifier->Change();
if (envChange & EChangesLocale )
CEikonEnv::InfoWinL(_L(""), _L(""));
else if (envChange & EChangesMidnightCrossover)
CEikonEnv::InfoWinL(_L("Midnight Crossed"), _L(""));
else if (envChange & EChangesThreadDeath)
CEikonEnv::InfoWinL(_L("Thread Died"), _L(""));
else if (envChange & EChangesPowerStatus)
CEikonEnv::InfoWinL(_L("Change in Power Status"), _L(""));
else if (envChange & EChangesSystemTime)
CEikonEnv::InfoWinL(_L("system time changed"), _L(""));
else if (envChange & EChangesFreeMemory)
CEikonEnv::InfoWinL(_L("free memory level crossed"), _L(""));
else if (envChange & EChangesOutOfMemory)
CEikonEnv::InfoWinL(_L("No Mem"), _L(""));

This page was last modified on 23 July 2012, at 10:56.
44 page views in the last 30 days.