Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Data handler applications must implement CAknAppUi::OpenFileL (Known Issue)

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Platform(s): S60 3rd Edition, S60 3rd Edition, FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Created: User:Technical writer 1 (22 Feb 2007)
Last edited: hamishwillee (19 Jun 2012)


When letting the system find and launch the handler application for a file with a recognized MIME type, the handler receives a call to its CAknDocument::OpenFileL() implementation. However, if the handler application is already running in the background, the OpenFileL() call for the document class is not received.


In addition to CEikDocument::OpenFileL(), data handler applications in S60 must also provide an implementation for CAknAppUi::OpenFileL().

A common way to solve this is to redirect the call to document class in CAknAppUi::OpenFileL():

void CHandlerAppUi::OpenFileL( const TDesC& aFileName )
CHandlerDocument* doc = static_cast<CHandlerDocument*>( Document() );
doc->OpenFileL( ETrue, aFileName, iEikonEnv->FsSession() );

If the handler application is running in the background, the calling application must call TApaTask::SwitchOpenFile():

TBool CCallingAppUi::RefreshDocumentFileL( const TUid& aUid, const TDesC& aFileName )
TApaTaskList taskList( iCoeEnv->WsSession() );
// Find handler application by its UID
TApaTask task = ( taskList.FindApp( aUid ) );
if ( task.Exists() )
// Calls CAknAppUi::OpenFileL(), requires SwEvent capability
User::LeaveIfError( task.SwitchOpenFile( aFileName ) );
return ETrue;
return EFalse;

If a file is launched from the S60 Web Browser or File Manager, a different approach is required as there will be no call to SwitchOpenFile(). The handler application itself can check for other instances of itself already running in the background. By default, the application framework brings the old instance to foreground, and terminates the new one. It is possible to change this behaviour by overriding PreDocConstructL() function from CAknApplication class:

void CHandlerApplication::PreDocConstructL()
CEikonEnv* env = CEikonEnv::Static();
// Check that this app is started as stand-alone
if (!env->StartedAsServerApp() && !env->EikAppUi())
RWsSession& ws = env->WsSession();
const TInt myWgId = env->RootWin().Identifier();
TInt wgId = 0;
TUid uid(AppDllUid());
// Look for another instance of this app
while (wgId >= 0)
if (wgId && wgId != myWgId) // Another instance found -> close it
TApaTask other(ws);
other.EndTask(); // Requires SwEvent capability
CApaWindowGroupName::FindByAppUid(uid, ws, wgId);
// call PreDocConstructL from base class

Note that above code works only for stand-alone (non-embedded) handler applications, and required SwEvent capability.

See also:

This page was last modified on 19 June 2012, at 01:52.
471 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.