Using Environment Change Notifier

Environment Change Notifier is provided so that an application can be notified of changes in the environment such as a switch in locale, crossing over past midnight and so on.

The TChanges enumerator lists the possible events. This set of events may be extended as the operating system evolves.


An environment change notifier is an instance of a CEnvironmentChangeNotifier class. This is an active object which allows an application to respond to change events easily. These change events are generated by a kernel side change notifier service. The CEnvironmentChangeNotifier class uses the kernel side change notifier service through an RChangeNotifier handle.

An application supplies a callback function to CEnvironmentChangeNotifier when it is constructed.

When an outstanding request for change events completes, CEnvironmentChangeNotifier issues another request for change events before calling the callback function (encapsulated in a TCallBack).

The implementation of the callback function depends on the application but, typically, it would flag the required changes and schedule other changes either to the application's engine or the application's user interface.

Programs can use Environment Change Notifier to request for notifications for the following changes:

  • change of system locale

  • system time passes midnight

  • system time changes

  • any thread dies

  • status of the power supply changes


To use the Environment Change Notifier, an application must perform the following:

  1. Implement a callback function to handle the environment change.

    TInt CExHandleNotification::ChangeLangSettings()
         //Code for changing the language settings.
  2. Construct a CEnvironmentChangeNotifier object using its NewL() function, specifying the active object priority and a pointer to the callback function encapsulated in a TCallBack object.

    NewL() also adds this CEnvironmentChangeNotifier active object to the current active scheduler.

        //Creating a notifier object with ChangeLangSettings as the callback function.
                    CEnvironmentChangeNotifier envNotifier = CEnvironmentChangeNotifier::NewL( EActivePriorityDefault,TCallBack(CExHandleNotification::ChangeLangSettings, this) );
  3. Issue a request for change events by calling the Start() member function.

Whenever a request completes, CEnvironmentChangeNotifier issues another request for change events before the callback function is invoked.

The first call to the callback function occurs immediately after the first call to Start(). This is because of the way the underlying change notifier service is implemented; the changes reported are those defined by the TChanges enum.

To stop the environment change notifier, an application must:

  1. Call CEnvironmentChangeNotifier's Cancel() function. Note that this is a member of the CActive base class.

  2. Delete the CEnvironmentChangeNotifier object.