Search code examples
c++qmlblackberry-10

Detect bb10 application goes to background


First this is my first development using bb10 sdk and also with qml + c++, I had I'm trying to capture the moment when the user slids from the blackberry logo, to minimize or switch app. Acording to their official documentation http://developer.blackberry.com/native/documentation/core/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/c_appfund_applifecycle.html

There is a state windows NAVIGATOR_WINDOW_INACTIVE that comes when the invisible() method is called,

the thing here: is that the documentation and searches I've done on internet, doesn't explain anything about were to override a method that listens for this event.

Any help would be greatly appreciated.


Solution

  • You need to create a subclass of QObject. If you use the project creation wizard Momentics will do this for you as applicationui.hpp and applicationui.cpp. In this class declare the following slots in application.hpp:

    public slots:
      void asleep();
      void awake();
      void invisible();
      void thumbnail();
      void fullscreen();
    

    Then in the class creation function attach the Application signals to your slots:

    bool c = QObject::connect(Application::instance(), SIGNAL(asleep()),
            this, SLOT(asleep()));
    Q_ASSERT(c);
    
    c = QObject::connect(Application::instance(), SIGNAL(awake()),
            this, SLOT(awake()));
    Q_ASSERT(c);
    
    c = QObject::connect(Application::instance(),
            SIGNAL(invisible()), this, SLOT(invisible()));
    Q_ASSERT(c);
    
    c = QObject::connect(Application::instance(),
            SIGNAL(thumbnail()), this, SLOT(thumbnail()));
    Q_ASSERT(c);
    
    c = QObject::connect(Application::instance(),
            SIGNAL(fullscreen()), this, SLOT(fullscreen()));
    Q_ASSERT(c);
    
    Q_UNUSED(c);
    

    Then define the slot functions to perform what you need to do when the application state changes into the one corresponding to the signal (I've only included one here):

    void applicationui::asleep() {
        //configure application for sleep mode. Suspend or reduce processing, etc.
    }