A view can be deactivated by either switching views or by closing the application (the view is deleted in both cases). If an application needs to remove the MSK (or any softkey command) from the stack while in view deactivation, the application must make sure that RemoveCommandFromStack is not called when the UI (that is, the whole application) is closed. See below for an example code snippet:
void CPslnGeneralThemeView::DoDeactivate() { RemoveCommandFromMSK(); CPslnBaseView::DoDeactivate(); } void CPslnGeneralThemeView::RemoveCommandFromMSK() { CEikButtonGroupContainer* cbaGroup = Cba(); // Check if model exists => indicates that UI is not exiting. if ( cbaGroup && iPslnUi->Model() ) { cbaGroup->RemoveCommandFromStack( KPslnMSKControlID, EPslnCmdAppDownload); cbaGroup->RemoveCommandFromStack( KPslnMSKControlID, EpslnCmdAppActivate); } }