My application is running in background (invisible). Now, the application needs to know whether the user interface is displayed in landscape or portrait mode. This can be done (for instance) this way:
CAknAppUiBase::TAppUiOrientation orientation = iAppUi->Orientation();
if (CAknAppUiBase::EAppUiOrientationPortrait == orientation) ...
This works fine, as long some other GUI application is started. But when the homescreen is shown then this does not work, because the homescreen is shown everytime in portrait mode (at least on my test device, the Nokia 5800XM).

Is there a way to fix this issue, e.g. to detect whether the homescreen is the current view?