View Architecture activates wrong view?

Login to reply to this topic.
Sun, 2003-12-14 07:05
Joined: 2003-10-17
Forum posts: 16
Hi, I'm using the view architecture and a call to 'ActivateViewL' results in the wrong view being displayed.  I know that each view returns the correct id and that I'm activating the write view because I've traced the execution through with the debugger.

I declare my views like this:
Code:
   iView1 = View1::NewL(ApplicationRect());
   RegisterViewL((MCoeView&)*iView1 );
   AddToStackL((MCoeView&)*iView1 , (CCoeControl*)iView1 );

   iView2 = View2::NewL(ApplicationRect());
   RegisterViewL((MCoeView&)*iView2);
   AddToStackL((MCoeView&)*iView2, (CCoeControl*)iView2);

   iView3 = View3::NewL(ClientRect(), this);
   RegisterViewL((MCoeView&)*iView3);
   AddToStackL((MCoeView&)*iView3, (CCoeControl*)iView3);

   iView4= View4::NewL(ClientRect(), this);
   RegisterViewL((MCoeView&)*iView4);
   AddToStackL((MCoeView&)*iView4, (CCoeControl*)iView4);

   iView5= View5::NewL(ClientRect(), this);
   RegisterViewL((MCoeView&)*iView5);
   AddToStackL((MCoeView&)*iView5, (CCoeControl*)iView5);

The view ID's are defined in the following manner:
Code:
static const TUid KUidView1 = { 0x100000E1 };
static const TUid KUidView2 = { 0x100000E2 };
static const TUid KUidView3 = { 0x100000E3 };
static const TUid KUidView4 = { 0x100000E4 };
static const TUid KUidView5 = { 0x100000E5 };

Some of my views are activated in the method 'HandleForegroundEventL', and some are activated else where in my appui class, is this a problem.

Thanks, any help would be appreciated.

Sun, 2003-12-14 07:24
Joined: 2003-10-17
Forum posts: 16
One more thing...
Also, the problem seems to only occur in emulator.  When I put a break point in the 'ViewActivatedL' of my view, it actually gets called twice.  I always call 'DeactivateActiveViewL' before activating another view.
Tue, 2003-12-16 19:41
Anonymous (not verified)
Forum posts: 2043
View Architecture activates wrong view?
First, sideline, consider what happens if there is a leave in that ConstructL.. you do deregister the views in the destructor right?  Ouch.

Second, listen for the view activated event.  And when it happens, on the window call SetPosition(0) to ensure it is on top.

Problem solved?
Tue, 2003-12-16 23:26
Joined: 2003-10-17
Forum posts: 16
View Architecture activates wrong view?
No, I deregister the views in the destructer, and in the view activated event I call Window().SetOrdinalPosition(0).  

In my docs SetPosition is listed as 'void SetPosition(const TPoint& aPosition)', how would calling this method ensure it is on top.  It just sets the point at which the control is displayed in the window it is owned by.
Wed, 2003-12-17 08:56
Anonymous (not verified)
Forum posts: 2043
View Architecture activates wrong view?
ah, I meant SetOrdinalPosition().  My bad memory, sorry.

What happens if RegisterViewL leaves, and you DeregisterView in the destructor?

TInt RegErr;
iView1 = View1::NewL(ApplicationRect());
TRAP(RegErr,RegisterViewL(*iView1));
if(KErrNone != RegErr)
  {
  delete iView1;
  iView1 = NULL;
  User::Leave(RegErr);
  }
AddToStackL(*iView1,iView1);
.. repeat for each view ..

So, to trace the wrong view thing; what does the View1::ViewId() look like?
Fri, 2004-01-23 10:48
Joined: 2003-05-15
Forum posts: 53
problems...
Quote
Some of my views are activated in the method 'HandleForegroundEventL', and some are activated else where in my appui class, is this a problem
I guess your problems is properly here.
The first time your app is activated you get a notification in this function and probably you reactivate the very same view.
this function is triggered also when a dialog that was over your view appears or is dismissed ... clearly you don't want to reactivate the view because of it. Sad
You have to be very carefully when you implements HandleForegroundEventL.
  • Login to reply to this topic.