×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    15

    [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Hi everybody,
    I'm facing a little problem with a little app coded with the 5th edition SDK, that is running in the background most of the time.

    My problem is that I don't know how to catch the following event: the user pushes the menu key => the phone switches from idle/home screen to menu screen (or in the other way).
    Let me join some screenshots since I don't know if I'm clear enough :
    <--->

    So, does anyone know how to catch such events in my app ?
    For information, all the other events (keypresses, stylus, window reordering) are catched in this method : void CMyProggyAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) via a switch(aEvent.Type()) block...

    Thanks a lot,
    Olivier

  2. #2
    Nokia Developer Champion
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,348

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Hi.

    Here is an example which gets the UID of the foreground application:
    Code:
    void C***::HandleWsEventL(const TWsEvent &aEvent, CCoeControl *aDestination)
    {
       switch (aEvent.Type())
       {
          case EEventFocusGroupChanged:
          {
             // You can now find out the UID of the foreground application using the following code:
             RWsSession ws;
             ws.Connect();
             CleanupClosePushL(ws);
             TApaTaskList taskList = TApaTaskList(ws);
             TApaTask foregroundTask = taskList.FindByPos(0);
             CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(ws, foregroundTask.WgId());
             TInt32 foregroundUid = wgName->AppUid().iUid;
             
             ////
             //// your code here
             ////    
                   
             CleanupStack::PopAndDestroy(2); // wgName, ws
             break;
          }
          
          // Starting from S60 3.x, pressing End key will terminate application.
          // We don't want this to happen in this application, so we have to handle
          // End key event (KAknUidValueEndKeyCloseEvent).
          case KAknUidValueEndKeyCloseEvent:
                break;
                
          default:
             // Pass on to default handler
             CEikAppUi::HandleWsEventL(aEvent, aDestination);
       }
    }
    Also see this article - Capturing foreground events

  3. #3
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Check Wiki for focus changing monitoring in background applications, there should be a ready made example available.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    15

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Thanks a lot for your replies, I'll check this ASAP.

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    15

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Hi AAM,
    I'm sorry but the code you provided is not working with my app.
    The EEventFocusGroupChanged event type is never received by my app, so I can't reach the code you provided.
    Also, the HandleWsEventL method is never reached when switching from Idle screen to Menu (that's my worst problem in fact).

    Something that I haven't said : my app is running in the background but is always on top. What I want is to enable this app to detect every time the user launches or closes any application (this detection is fine with the EEventWindowGroupsChanged event, except for idle/menu switch).

    I haven't tested the wiki example yet, I'll tell you ASAP.

  6. #6
    Nokia Developer Champion
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,348

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Then check wiki example. I've already test it and it works correctly.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    15

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    OK, I started implementing the wiki example, this sould do the trick.

    The thing is that I don't know how to pass the callback into the constructor (I thought it would be a void * pointer as in C code instead of MFgrCallBack, I'm a noob in C++).

    For example, here's my app UI constructor (I supposed that the foreground observer is a member of the app UI ?) :
    Code:
    void CMyProggyAppUi::ConstructL()
    {
    	// stuff
            ...
    
    	RWsSession ws = CEikonEnv::Static()->RootWin();
    	iForegroundObserver = CFgrObserver::NewL(ws, what_should_i_insert_here);
    
            // moar stuff
            ...
    }
    
    ...
    
    void what_should_i_insert_here(TUid aUID)
    {
            // do stuff due because background apps focus changed
            ...
    }
    Could you please help (again) ?
    Thanks !

  8. #8
    Nokia Developer Champion
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,348

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Here is an implementation:

    ////////////
    AppUi.h
    ////////////

    Code:
    class C***AppUi : public CAknAppUi, public MFgrCallBack
     	{
    ...
    private : // from MFgrCallBack
    	void ForegroundEventL(TUid aAppUid);
    ...	
    private : // Data
    	RWsSession      iWsSession; 
    	CFgrObserver*    iFgrObserver;
    	};
    ////////////
    AppUi.cpp
    ////////////

    Code:
    void C***AppUi::ConstructL()
    	{
    	...
    	//  Initialize foreground monitor
    	User::LeaveIfError(iWsSession.Connect());
    	iFgrObserver=CFgrObserver::NewL(iWsSession,*this);
    	...
    	}
    
    C***AppUi::~C***AppUi()
    	{
    	...
    	   delete iFgrObserver;
    	   iWsSession.Close();
    	...
    	}
    
    void C***AppUi::ForegroundEventL(TUid aAppUid)
    	{
    	//... 
            //... foreground app changed and now it's UID now in aAppUid
            //... 
    	}

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    15

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    It works ! Well, I'm not detecting the IDLE screen UID, but the "Quick Menu" UID instead. It doesn't matter though.
    Thank you so much !

    Regards,
    Olivier

  10. #10
    Nokia Developer Champion
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,348

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Idle screen UID is 0x102750F0, menu UID is 0x101F4CD2

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    3

    Re: [5th ED] How to detect switching from home/idle screen to the menu screen ?

    Thanks, was looking for the same solution.

Similar Threads

  1. Replies: 2
    Last Post: 2007-11-10, 13:19
  2. Replies: 0
    Last Post: 2005-01-14, 04:02
  3. Replies: 0
    Last Post: 2005-01-14, 04:01
  4. UI: Full Screen Mode
    By GENERAL_INFO in forum Symbian User Interface
    Replies: 3
    Last Post: 2004-11-22, 06:27
  5. Menu screen
    By sunilpai123 in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2004-05-24, 09:40

Posting Permissions

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