Activity Manager Tutorial

This section explains how to implement Activity Manager.

An object of the CUserActivityManager class must be included as a member of the component which need to react to activity and inactivity.


  1. Create an object of CUserActivityManager.

  2. Create an activity callback function implementing the transition to device activity.

  3. Create an inactivity callback function implementing the transition to device inactivity.

  4. Call the CUserActivityManager::StartL() function using the object of CUserActivityManager. This function accepts the following three arguments:
    • an integer representing the inactivity interval in seconds,

    • the inactivity callback, and

    • the activity callback.

    The callback arguments are instances of TCallBack.

Activity manager example

#include <activitymanager.h>
…
// Activity Manager instance is created and started

void CSomeComponent::ConstructL()
    {
    …
    iActivityManager = CUserActivityManager::NewL( CActive::EPriorityStandard );

    iActivityManager->StartL( iTimeout,
                   TCallBack( HandleInactiveEvent, this ),
                   TCallBack( HandleActiveEvent, this ) );
    …
    }
…
// Handles inactive event
TInt CSomeComponent::HandleInactivityEvent( TAny* aPtr )
    {
    // Code to be executed in case of user inactivity
    …
    }

// Handles active event
TInt CSomeComponent::HandleActivityEvent( TAny* aPtr )
    {
    // Code to be executed in case of user activity after an inactivity period.
    …
    }
Related concepts
Activity Manager Overview