Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android Activity Lifecycle in Qt.

Android Activity Lifecycle in Qt.

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 5 Posters 7.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NKinney.Econolite
    wrote on last edited by
    #1

    I asked this question before but I got no replies. I will ask again using different words. I have a test App that does some work and when I select home it goes into the background but it keeps running.

    I need to shut down part of my app when it is in the background. This will help me from killing the battery. How do you get notified about this in a Qt App. I don’t see how to get to onPause() or onResume(). How do you find out when you’re going into or coming out of the background?

    1 Reply Last reply
    1
    • T Offline
      T Offline
      terenty
      wrote on last edited by
      #2

      Hi,
      Actually I belive Qt5.2 introduces such a feature, have a look at "QGuiApplication::applicationStateChanged":http://doc-snapshot.qt-project.org/qt5-stable/qguiapplication.html#applicationStateChanged signal.
      Without this, you would have to register your C++ native state handling methods into Java environmet and then modify QtActivity.java in order to make it call these methods upon app state change, see how its done "here":http://sourceforge.net/p/erebusrpg/code/ci/master/tree/main.cpp#l72 & "here":http://sourceforge.net/p/erebusrpg/code/ci/master/tree/android/src/org/kde/necessitas/origo/QtActivity.java#l87

      1 Reply Last reply
      1
      • N Offline
        N Offline
        NKinney.Econolite
        wrote on last edited by
        #3

        Thanks that worked for me.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          habamax
          wrote on last edited by
          #4

          [quote author="terenty" date="1386097969"]Hi,
          Actually I belive Qt5.2 introduces such a feature, have a look at "QGuiApplication::applicationStateChanged":http://doc-snapshot.qt-project.org/qt5-stable/qguiapplication.html#applicationStateChanged signal.[/quote]

          I can't find the way to use it in regular QML application. Is there a doc or manual about it?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            habamax
            wrote on last edited by
            #5

            Well, looks like Connections to rescue here:

            @
            Connections {
            target: Qt.application
            onStateChanged: {
            switch (Qt.application.state) {
            case Qt.ApplicationSuspended:
            case Qt.ApplicationHidden:
            break
            case Qt.ApplicationActive:
            break
            }
            }
            }
            @

            A E 2 Replies Last reply
            1
            • H habamax

              Well, looks like Connections to rescue here:

              @
              Connections {
              target: Qt.application
              onStateChanged: {
              switch (Qt.application.state) {
              case Qt.ApplicationSuspended:
              case Qt.ApplicationHidden:
              break
              case Qt.ApplicationActive:
              break
              }
              }
              }
              @

              A Offline
              A Offline
              ahmad88me
              wrote on last edited by
              #6

              @habamax It works thank you

              1 Reply Last reply
              0
              • H habamax

                Well, looks like Connections to rescue here:

                @
                Connections {
                target: Qt.application
                onStateChanged: {
                switch (Qt.application.state) {
                case Qt.ApplicationSuspended:
                case Qt.ApplicationHidden:
                break
                case Qt.ApplicationActive:
                break
                }
                }
                }
                @

                E Offline
                E Offline
                Elsiete
                wrote on last edited by
                #7

                @habamax Work like a charm, thanks

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved