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. catch app close on Android and iOS
Forum Updated to NodeBB v4.3 + New Features

catch app close on Android and iOS

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 2.2k Views 2 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.
  • M Offline
    M Offline
    Marek
    wrote on last edited by
    #1

    Hi all,

    I need to save some data before application closes, on Android I have signal when backbutton is pressed and I can save data. On iOS there is no back button, OS will close my app at some point, can I be sure in code to catch this and save data before closing ?

    Best.
    Marek

    raven-worxR 1 Reply Last reply
    0
    • M Marek

      Hi all,

      I need to save some data before application closes, on Android I have signal when backbutton is pressed and I can save data. On iOS there is no back button, OS will close my app at some point, can I be sure in code to catch this and save data before closing ?

      Best.
      Marek

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Marek
      use the QCoreApplication::aboutToQuit() signal or after app.exec() (might be already too late though) in your main().
      This might only work when the running app is closed by the user and not when the system forcefully decides to shutdown your application.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Marek
        use the QCoreApplication::aboutToQuit() signal or after app.exec() (might be already too late though) in your main().
        This might only work when the running app is closed by the user and not when the system forcefully decides to shutdown your application.

        M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        @raven-worx Thanks. So, will this work on iOS ? I mean OS will close application in ordinary manner or forcefully?

        raven-worxR 1 Reply Last reply
        0
        • M Marek

          @raven-worx Thanks. So, will this work on iOS ? I mean OS will close application in ordinary manner or forcefully?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Marek
          i am not quite sure, since i am not very experienced with iOS. Give it a try by switching the app to background and close it afterwards from the "task manager".
          On Android the system might stop your application (when in background) in order to claim back resources.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          M 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @Marek
            i am not quite sure, since i am not very experienced with iOS. Give it a try by switching the app to background and close it afterwards from the "task manager".
            On Android the system might stop your application (when in background) in order to claim back resources.

            M Offline
            M Offline
            Marek
            wrote on last edited by
            #5

            @raven-worx In short it would be best to save data when app is going in background (this will catch iOS and Android case ) and when backbutton on Android is used, right?

            raven-worxR 1 Reply Last reply
            0
            • M Marek

              @raven-worx In short it would be best to save data when app is going in background (this will catch iOS and Android case ) and when backbutton on Android is used, right?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @Marek said in catch app close on Android and iOS:

              In short it would be best to save data when app is going in background (this will catch iOS and Android case )

              probably yes, you can try to check the application state (QML)
              This is actually the better approach than my first advice!

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              M 1 Reply Last reply
              3
              • raven-worxR raven-worx

                @Marek said in catch app close on Android and iOS:

                In short it would be best to save data when app is going in background (this will catch iOS and Android case )

                probably yes, you can try to check the application state (QML)
                This is actually the better approach than my first advice!

                M Offline
                M Offline
                Marek
                wrote on last edited by
                #7

                @raven-worx Thanks, I will do some testing but this seems to solve my problem.

                raven-worxR 1 Reply Last reply
                0
                • M Marek

                  @raven-worx Thanks, I will do some testing but this seems to solve my problem.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by raven-worx
                  #8

                  @Marek
                  in QML:

                  application.state == Qt.ApplicationSuspended
                  // and the following, depending if the state also changes to 'suspended' on quit or not
                  application.aboutToQuit.connect(saveFunction)
                  

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  1

                  • Login

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