×

Discussion Board

Results 1 to 13 of 13

Thread: Switching Views

  1. #1
    Regular Contributor
    Join Date
    May 2008
    Posts
    139

    Thumbs up Switching Views

    What is the correct way to switch views?

    I have a CAknViewAppUi derived UI and CAknView derived views. I use following code to switch my views.

    Code:
    void CMyUi::SelectView(TBool aFlag) {
    
        if(aFlag) {
            // Do not create view if it was already created
            if(!iFirstView ) {
                iFirstView = CFirstView::NewLC(this);
                AddViewL(iFirstView );
                CleanupStack::Pop(iFirstView );
            }
    
                ActivateLocalViewL(iFirstView->Id());
    
        } else {
    
                if(!iSecondView) {
                iSecondView= CSecondView::NewLC(this);
                AddViewL(iSecondView);
                CleanupStack::Pop(iSecondView);  
        }
    
         ActivateLocalViewL(iSecondView->Id());
        
      }
    
    }
    The problem is some independent code crashes if I switch views but works fine if I do not switch view (as posted in another thread). Hence I am not sure if I am switching the views correctly.

    I also get Viewsrv 11 randomly after I switch the view. There is no blockage into the code and all active obhects are asynchronous.

    I also added following code without much help

    After Activating second view, delete first view
    Code:
        ...
        ...
        ActivateLocalViewL(iSecondView->Id());
    
        if (iFirstView)
        {
            RemoveView(iFirstView->Id());
             delete iFirstView;
             iFirstView= NULL;
        }
        ...
    Any help will be appreciated.

    Thanks
    Last edited by gammav; 2008-06-30 at 05:55.

  2. #2
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Switching Views

    Why are you constructing the views dynamically? Adding them once, in UI's ConstructL and then activating them as needed is good enough and safe.
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    6

    Post Re: Switching Views

    Hi,

    View switching is being done correctly here. Crashes/Viewsrv 11 panic can occur if some weird operation is being performed in ViewActivatedL(); or ViewDeactivatedL(); functions inside the view. The other reason for Viewsrv 11 panic is that some asynchronous operation being performed inside the view, is not completed before view is deactivated. Could you cross check these issues in your code?

  4. #4
    Regular Contributor
    Join Date
    May 2008
    Posts
    139

    Re: Switching Views

    Quote Originally Posted by ltomuta View Post
    Why are you constructing the views dynamically? Adding them once, in UI's ConstructL and then activating them as needed is good enough and safe.
    How it matters? Anyway, I have modified as you suggested and added follwoing in ConstructL but now problem is elevated.

    Code:
    iFirstView = CFirstView::NewLC(this);
    AddViewL(iFirstView );
    CleanupStack::Pop(iFirstView );
    iSecondView= CSecondView::NewLC(this);
    AddViewL(iSecondView);
    CleanupStack::Pop(iSecondView);
    The code which was crashing after switching view is now crashing for the start. Hence, this could be due to creating the two views. Is there anything done wrongly in creating or switching views? am I missing something?

  5. #5
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Switching Views

    well first of all no need to use NewLC, but just use NewL and no need to Pop either.

    so it will be like:
    iFirstView = CFirstView::NewL(this);
    AddViewL(iFirstView );
    iSecondView= CSecondView::NewL(this);
    AddViewL(iSecondView);

    // also you should activate one of the views here, say first...
    ActivateLocalViewL(iFirstView->Id());
    Amit Kankani
    Nokia Developer Champion

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    6

    Re: Switching Views

    Hi,
    You can create as many views as you want and add them to CAknViewAppUi derived class. But there should be some default view which will show up when application starts. You can use the code below:

    iFirstView = CFirstView::NewLC(this);
    AddViewL(iFirstView );
    CleanupStack::Pop(iFirstView );
    iSecondView= CSecondView::NewLC(this);
    AddViewL(iSecondView);
    CleanupStack::Pop(iSecondView);
    SetDefaultViewL(*iFirstView); //set the first view as the default
    //view.

  7. #7
    Regular Contributor
    Join Date
    May 2008
    Posts
    139

    Re: Switching Views

    Thanks guys for responding. Problem seems to be with AddView. If I do not add second view, everything works fine and crash in urelated function is not observed. I am puzzled before code which is crashing is very unrelated to both the views

    vermaalok, SetDefaultViewL is already done.

    amit, ActivateLocalViewL is already done as shown in the code. NewLC is used to protect against error in AddViewL

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    6

    Re: Switching Views

    Hi,
    Could you share your view's DoActivateL() and DoDeActivateL() functions? and the constructor where BaseConstructL() is being called? Is the view defined in .rss file and passed as a parameter in BaseConstructL()?

  9. #9
    Regular Contributor
    Join Date
    May 2008
    Posts
    139

    Re: Switching Views

    Quote Originally Posted by vermaalok View Post
    Hi,
    Could you share your view's DoActivateL() and DoDeActivateL() functions? and the constructor where BaseConstructL() is being called? Is the view defined in .rss file and passed as a parameter in BaseConstructL()?
    Hi, Below is code for view in problem.

    Code:
    void CFirstView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, 
    										 TUid /*aCustomMessageId*/, 
    								   const TDesC8& /*aCustomMessage*/)
    	{
    	if(!iFirstScreen)	
    		{
    		TRect r = ClientRect();
    		// construct control and set parent
    		iFirstScreen = CFirstcreen::NewL(r);
    		iFirstScreen->SetMopParent(this);
    
    		//TResourceReader reader;
    		//CEikonEnv::Static()->CreateResourceReaderLC(reader, R_SETTINGS);
    		//CleanupStack::PopAndDestroy();	
    
    		AppUi()->AddToViewStackL(*this, iFirstScreen);
    		iFirstScreen->ActivateL();
     	
    		}
    	}
    
    void CFirstView::DoDeactivate()
    	{
    	if(iFirstScreen)	// if setting list has been created
    		{
    		// remove setting list from stack
    		AppUi()->RemoveFromViewStack(*this, iFirstScreen);
    
    		// clean up 
    		delete iFirstScreen;
    		iFirstScreen= NULL;
    		}
    	}
    
    void CFirstView::ConstructL()
    	{
    	// construct from resource
    	BaseConstructL(R_FIRSTVIEW);
    	
    	}
    Below is RSS

    Code:
    RESOURCE AVKON_VIEW r_firstview
    	{
    	cba=R_AVKON_SOFTKEYS_OPTIONS_DONE;
    	menubar=r_first_menubar;
    	}
    Thanks

  10. #10
    Regular Contributor
    Join Date
    May 2008
    Posts
    139

    Re: Switching Views

    Seems like I can not add viewes dynamically. basically, I was trying to save memory to not initiallize all the views unless requires. However, that appears to be problem. Any view added after ActivateLocalView seems to be creating problem or else I am doing something wrong. If I add all views before ActivateLocalView, things seems to work fine.

    Will play more!

  11. #11
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Switching Views

    well that is not the problem, coz in my code i have been doing ActivateLocalView (for a created view) and then creating all the other views.

    anywayz it could be some other problem !
    Amit Kankani
    Nokia Developer Champion

  12. #12
    Regular Contributor
    Join Date
    May 2008
    Posts
    139

    Re: Switching Views

    Quote Originally Posted by amitkankani View Post
    well that is not the problem, coz in my code i have been doing ActivateLocalView (for a created view) and then creating all the other views.

    anywayz it could be some other problem !
    ok, then I must be doing something wrong, because adding all views at once consume so much memory and definitely something I do not want. Earlier I was adding dynamically and it is giving problem. Just by changing to one time allocation below activate has solved the problem. I really look forward to going back to dynamic approach.

    Any insight from code I posted?

  13. #13
    Registered User
    Join Date
    Jun 2008
    Posts
    6

    Re: Switching Views

    Code below seems correct. The only problem I can think of is that there might me some issue with the control inside the view. Control might be doing some processing but it is not completed when the destructor of the same is called.

Similar Threads

  1. Switching views with "memory" (S60 3rd)
    By uttumuttu in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-07-20, 15:55
  2. Switching Views
    By oiram1 in forum Symbian User Interface
    Replies: 1
    Last Post: 2006-07-14, 10:52
  3. Switching views on a Dialog-based Views App
    By net314 in forum Symbian User Interface
    Replies: 4
    Last Post: 2003-08-26, 21:05
  4. switching views, without using containers
    By s3ni in forum Symbian User Interface
    Replies: 13
    Last Post: 2003-07-23, 05:17
  5. Switching Views
    By haluan in forum Symbian
    Replies: 0
    Last Post: 2003-07-11, 12:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×