I had the same issues as described in this thread and finally found a solution for this problem. The trick is to use an asynchronous callback in order to create the dialog on startup from the correct context. Well, here we go:
Add following to your AppUi or View header file, whereever you like:
// Creates and runs the dialog.
// Invoked by async. callback. Forwards call to "OnShowDialog" to get out of the static class scope.
static TInt StaticOnShowDialog(TAny* aPtr);
// Asynchronous callback (CActive, one-shot).
In the implemenation you have to do following on startup of your AppUi/view:
The active scheduler will enqueue the asynchronous callback and invoke the class method "StaticOnShowDialog" of your class from the proper context:
TCallBack cb(MyClass::StaticOnShowDialog, this); // We're passing the "this" pointer here, we'll use it later in the static callback.
iAsyncCb = new (ELeave) CAsyncCallBack(cb, CActive::EPriorityStandard);
// Enqueus the callback in the active scheduler.
Finally, in the method "OnShowDialog()" you can create your dialog:
TInt MyClass::StaticOnShowDialog(TAny* aPtr)
// The given pointer is the object pointer to MyClass, so we can cast it safely.
// Create and run the dialog ...