You Are Here:

Community: Blogs

Paul Todd's Forum Nokia Blog

Displaying something when starting up your application

Paul.Todd | 15 December, 2008 23:55

One of the commonest question that seems to be asked is how to display
a dialog or a note when the application starts. Due to the way the UI framework starts, its not suitable or even appropriate to block the main thread before any iews and the main view's container are created. This causes all sorts of problems such as the background being blank and wierd crashes and issues. Almost all of these revolve around the face that the UI is not fully constructed before being used so its not possible to safely use it at his point.

The way to address this is to create an active object that is scheduled to run
but with an idle priority. This object will be run once there is nothing to do and so this gives the UI framework the opportunity it initialize itself and allow he container view to be created and displayed.

Luckily its a simple matter to create the code to do this. The way I have chosen
to do this is to use the CAsyncCallBack object with an idle priority. Of course
you can use for example your own active object or the CAsyncOneShot object to
do the same.

I recommend that the callback object be put in the main view rather than the appui
as this makes it easier to access the current view object. Of course if you
are not using the view framework then it is suitable to put it into the appui.

Three methods are needed:
void AddInitialCallbackL();
void DoStartupCallbackL();
static TInt StartupCallback(TAny* aAny);

The first method creates the callback, links it to an object and adds
the callback object to the active scheduler

The second method is 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.

The last method is the actual implementation of the callback that is in the object. This can do various things including kicking off another active object. or this example a note is displayed.

For the sample code I have have chosen to put it in the main view of the application and not 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!
    iCallback->CallBack();
    }

TInt CView::StartupCallback(TAny* aAny)
    {
    CView* view = REINTERPRET_CAST(CView*, aAny);
    TRAP_IGNORE(view->DoStartupCallbackL());
    return EFalse;
    }

void CView::DoStartupCallbackL()
    {
    CAknInformationNote* note = new (ELeave) CAknInformationNote(ETrue);
    note->ExecuteLD(_L("Callback Executed"));
    }
That is all there is to getting a dialog, note or query up when your application is started

 

RSSComments

Useful code

virtual keyboard | 13/01/2009, 15:19

At least I've found what I need. Thanks Todd!

You must login to post comments. Login
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
User Rating: qfnZuserE5FratingQNx5E2E0000X