Archived:Sending custom message between views using Symbian C++

From Nokia Developer 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}}.

Remove from Archive?: This article has been marked for removal from archive, for the following reasons:
Looks valid on current versions of Symbian C++ to me!

The following example shows how to send custom messages from CAknView to another CAknView while activating the view.

Article Metadata
Tested with
Devices(s): Nokia N95
Platform(s): S60 3rd Edition, MR
S60 3rd Edition (initial release)
Platform Security
Signing Required: Self-Signed
Capabilities: None
Keywords: CAknViewAppUi
Created: tepaa (14 May 2008)
Last edited: hamishwillee (28 Sep 2012)


MMP file

The following capabilities and libraries are required:

LIBRARY avkon.lib

Header, sending custom message

#include <aknview.h>
const TUid KView1Id = {1};
const TUid KView2Id = {2};
const TUid KCustomMessageUid= {2}; // Your custom message uid
void CFirstView::HandleCommandL(TInt aCommand);

Source, sending custom message

void CFirstView::HandleCommandL(TInt aCommand)
switch ( aCommand )
case EOpenSecondView:
// Switch to view 2 and send a message Uid and a message
// Construct a message to send
TBuf8<255> customMessage;
customMessage.Copy(_L8("Message from firsto view"));
// Activate the second view and give the message as a parameter
AppUi()->ActivateLocalViewL(KView2Id, KCustomMessageUid, customMessage);

Header, receiving custom message

#include <aknview.h>
#include "CFirstView.h"
void CSecondView::DoActivateL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage);
HBufC8* iReceivedMessage;

Source, receiving custom message

void CSecondView::DoActivateL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage)
// Create Container
if (!iContainer)
iContainer = new (ELeave) CMyViewContainer2;
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
// 1. Check aCustomMessageId to handle aCustomMessage
// 2. You could check aPrevViewId if you were curious to know
// from where this view was called from.
if (aCustomMessageId==KCustomMessageUid)
// TODO: Do something with aCustomMessage
iReceivedMessage = aCustomMessage.AllocL();


When the second view is activated it can receive a custom message from the previous view.

This page was last modified on 28 September 2012, at 04:47.
46 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.