Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to start active objects

The following example code shows how active objects are started. While the example shows the creation of an active scheduler, in UI applications, an active scheduler is always provided.

LOCAL_C void doExampleL()
    {
        // Create and install the active scheduler
    CActiveScheduler* exampleScheduler=new (ELeave) CExampleScheduler;
    CleanupStack::PushL(exampleScheduler);
    CActiveScheduler::Install(exampleScheduler);

        // Create the service provider. Often, the
        // service provider is part of the active object
    CExampleServiceProvider* myServiceProvider=new (ELeave) CExampleServiceProvider;
    CleanupStack::PushL(myServiceProvider);

        // Create the active object and issue the
        // first asynchronous request
    CExampleActiveObject * myActiveObject=new (ELeave) CExampleActiveObject(myServiceProvider);
    CleanupStack::PushL(myActiveObject);
    myActiveObject->IssueRequest();

        // Now we can start the active scheduler
    CActiveScheduler::Start();

        // Remove the exampleScheduler and other
        // objects from cleanup stack and destroy them
    CleanupStack::PopAndDestroy(3);
    }