Hi all, I write a console application that can running in background, and if some new SMS arrived.
I will activate a GUI application.
Following is the implemenation:
TBool CDetector::StartAppL(const TDesC& aParam)
{
const TUid KAppUid( TUid::Uid( 0x2002A11C ) );
RWsSession aWsSession;
User::LeaveIfError( aWsSession.Connect() );
TApaTaskList aTaskList( aWsSession);
TApaTask aApaTask = aTaskList.FindApp( KAppUid );
const TBool bIsExist = aApaTask.Exists();
// Close the windows server session.
aWsSession.Close();
TInt nErrCode = KErrNone;
if ( bIsExist )
{
// The application is already running.
aApaTask.BringToForeground();
// Send the message.
if ( aParam.Length() > 0 )
{
// Convert the param to UTF-8 encoding
HBufC8* pParam8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
if ( NULL != pParam8 )
{
CleanupStack::PushL(pParam8);
// Send the message.
nErrCode = aApaTask.SendMessage(TUid::Uid(KUidApaMessageSwitchOpenFileValue ), *pParam8);
// Release the instance for the buffer.
CleanupStack::PopAndDestroy(pParam8);
}
}
}
else
{
RApaLsSession aApaLsSession;
// connect to AppArc server
User::LeaveIfError(aApaLsSession.Connect());
// The parameter is empty.
TThreadId nThreadId;
nErrCode = aApaLsSession.StartDocument(aParam, KAppUid, nThreadId, RApaLsSession::ELaunchNewApp);
aApaLsSession.Close();
}
return (KErrNone == nErrCode);
}
The problems is: If the GUI application is not launch yet, it will start through StartDocument, and it work fine.
While the GUI app is already running. Then the console application will crash.
And if I commented the line: SendMessage, of course, it will not crash since do nothing.
So my question is: how can we start the application in the console mode if the GUI is already running.
Thanks all!

Reply With Quote

