View a printable version of the current page.
  Wiki > Symbian Developer Network Public Wiki > ... > SDN Wiki Competition 2007 entries > How to start application from your code
  How to start application from your code
Added by newalex007, last edited by rodders on Feb 15, 2008  (view change)
Labels: 
(None)

  To start any application from your application if you know the application name is very useful feature. You can make your own application browser for example or find another way to use it.
   Basically to do this all you need is to call StartApp method of RApaLsSession with CApaCommandLine pointer as argument. It looks like this in example below -

arcSession.StartApp(*cmd). If application is already running somewhere in the background all that you need is just to bring it to foreground. It is done just like this - task.BringToForeground().

   Detailed code example with comments is below. This code was running on S60 with Symbian OS v.9.

// ---------------------------------------------------------------------------

// CMyAppEngine::StartApp()

// Start the app with aName as parameter

// ---------------------------------------------------------------------------

//

void CMyAppEngine::StartApp(const TDesC& aName)

{   

    //Check if application is already running in the background

    TApaTaskList tasks( CEikonEnv::Static()->WsSession() );

    TApaTask task = tasks.FindApp( aName );

    if ( task.Exists() )

    {

            //If it is already running then just bring it to foreground

            task.BringToForeground();

    }

    else

    {       

            // If application is not running, then create a new one

            CApaCommandLine* cmd = CApaCommandLine::NewLC();

            #ifdef EKA2

            cmd->SetExecutableNameL(aName);

            #else

            //file server session

            RFs fsession;

            User::LeaveIfError(fsession.Connect());

            CleanupClosePushL(fsession);

            TFindFile iFile( fsession );

           User::LeaveIfError( iFile.FindByDir(aName, KNullDesC) );

            cmd->SetLibraryNameL(iFile.File());

            #endif

            cmd->SetCommandL(EApaCommandRun);

            RApaLsSession arcSession;

           //connect to AppArc server

           User::LeaveIfError(arcSession.Connect());         CleanupClosePushL(arcSession);

           User::LeaveIfError( arcSession.StartApp(*cmd) );

           arcSession.Close();

           #ifndef EKA2

            CleanupStack::PopAndDestroy(1);

            #else

            CleanupStack::PopAndDestroy(2);

            #endif

    }

}

   There is simple example code to demonstrate how to use this function below.

_LIT(KAppName, "Calendar");

//iEngine is pointer to the object of CMyAppEngine type

iEngine->StartApp(KAppName);

   Hope this article will save your time if you will need to start any application from your code. Thank you for attention.

[live-web] Interactive Services Terms & Conditions of use | Terms of use | Privacy policy | Media Center | Contact us | © 2008 Symbian