Display a dialog when the application starts

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: Paul.Todd (15 Dec 2008)
Last edited: hamishwillee (20 Jul 2012)

Due to the asynchronous nature of the AVKON/EIKON framework, the active scheduler needs to have at least one reschedule to setup all the components of the framework correctly. This means it is very bad practice to block the application in the ConstructL call to display a dialog.

The correct way is to create an active object that is triggered when there are no outstanding requests in the active scheduler and this displays the dialog correctly and ensures features such as the background are not white.

Three methods are typically needed. They are as follows:

1. void AddInitialCallbackL()

This creates the callback, links it to an object and adds the callback object to the active scheduler.

 // This sample is added to the view class of the application,
// though it could equally as well be added to the appui
// This is called from the DoActivateL of the view class.
void CView::AddInitialCallbackL()
TCallBack callback(StartupCallback, this);
iCallback = new (ELeave) CAsyncCallBack(callback, CActive::EPriorityIdle);
// Most people forget the step below, this schedules the active object!

2. static TInt StartupCallback(TAny* aAny)

The actual callback object function. The parameter passed in is the object so this can be cast to the correct type and then the method on that object can be called.

 TInt CView::StartupCallback(TAny* aAny)
CView* view = REINTERPRET_CAST(CView*, aAny);
return EFalse;

3. void DoStartupCallbackL()

The actual implementation of the callback that is in the object. This can do various things including kicking off another active object.

 void CView::DoStartupCallbackL()
CAknInformationNote* note = new (ELeave) CAknInformationNote(ETrue);
note->ExecuteLD(_L("Callback Executed"));
This page was last modified on 20 July 2012, at 10:29.
23 page views in the last 30 days.