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. Logging in a file issue with an app running in background with Qt 5.4 for Android.
Forum Updated to NodeBB v4.3 + New Features

Logging in a file issue with an app running in background with Qt 5.4 for Android.

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 3 Posters 3.1k 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.
  • L Offline
    L Offline
    lambda
    wrote on last edited by
    #1

    Hi,
    I'm developing an app logging the location in a file with Qt for Android.
    It seems that the data are not flushed in the file when the application runs in background.
    All the data in the buffer are flushed in the file only when the app get the focus.
    It seems it is a regression in Qt 5.4, because it was functionning fine using Qt 5.3.
    Calling flush() from the QTextStream doesn't bring any change.

    Is someone can confirm this point ?

    Regards

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      i think this is the behavior for apps.
      IIRC when you put them to the background you have some time to finish some things up before they get put to sleep.

      What you need in Android is called "service":http://developer.android.com/guide/components/services.html, which should do the logging. Probably it doesn't make sense to do this with Qt but with Java directly.

      --- 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
      0
      • L Offline
        L Offline
        lambda
        wrote on last edited by
        #3

        Thanks for your answer.
        But my purpose is to make a portable app, in order to targer other mobile environments in the future, it's why I'm writing it with Qt.

        The stange thing is that it was working as expected when I compiled with Qt 5.3, testing it on Jelly Bean and KitKat.
        This appears compiling the app with Qt 5.4.

        The thread proceeding the logging (which sould be the same thing than an Android service) is the thread created by the API Qt Location:

        source = QGeoPositionInfoSource::createDefaultSource(this);
        if (source) {
            connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                    this, SLOT(positionUpdated(QGeoPositionInfo)));
            source->startUpdates();
        }
        

        The logging is called somewhere further in the code from the slot function positionUpdated().

        There is no lost data when the app runs in background, if it is stopped by itself. All data are stored in a buffer and are flushed only when the app get the focus. It is a strange behaviour, I think, because if the app crash or is ended from Android, all data in the buffer are lost.
        I'm just a beginner in Qt, but it seems to me that this can be a bug in Qt 5.4. Don't you believe so ?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          [quote author="lambda" date="1422004855"]Thanks for your answer.
          But my purpose is to make a portable app, in order to targer other mobile environments in the future, it's why I'm writing it with Qt.
          [/quote]
          yes. but when Qt doesn't provide the platform specific work you have to do it yourself.

          [quote author="lambda" date="1422004855"]
          The stange thing is that it was working as expected when I compiled with Qt 5.3, testing it on Jelly Bean and KitKat.
          This appears compiling the app with Qt 5.4.
          [/quote]

          are you 100% sure?! Should be easy to test though. As i said you have some time your app runs (i think around ~30 sec) before it get to sleep.
          Just test it if it is still logging after a few minutes.

          Further you should ask the question on the "android-dev-list":http://lists.qt-project.org/mailman/listinfo/android-development

          --- 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
          0
          • L Offline
            L Offline
            lambda
            wrote on last edited by
            #5

            I tested again but i was 100% sure:
            With Qt 5.4:

            • The app runs, I controlled if the fix is OK with an other app:
              -> logging OK
            • The app sleeps: no more logging - fix OK
            • After 5 mn sleeping, the app runs again: logging OK and all data during the 5mn are in the logging file (I log also timestamp in the logging file)

            With Qt 5.3 not such behaviour (logging all the time, running and sleeping). I didn't tested again because I made several tests with Qt 5.3 in the past.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mike12779
              wrote on last edited by
              #6

              As of 5.4 there is a new setting you must set in the AndroidManifest.xml to keep the event loop running when your application is suspended. Maybe this is something you need to set.

              <!-- Background running -->
              <!-- Warning: changing this value to true may cause unexpected crashes if the
              application still try to draw after
              "applicationStateChanged(Qt::ApplicationSuspended)"
              signal is sent! -->
              <meta-data android:name="android.app.background_running" android:value="false"/>
              <!-- Background running -->

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lambda
                wrote on last edited by
                #7

                Thanks a lot for your answer.
                I made the change in the AndroidManifest.xml using apktool, but the app doesn't install no more, may because it is no more signed. I have to think about that.
                Is there a way to make the change directly from QtCreator ?
                Do you know a link to the documentation about this change from Qt5.3 to Qt5.4 ?
                Another problem concerns the unexpected crash conditions because we don't have any idea about the stability of an app build in that way, and my app have to run for several hours.

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  [quote author="lambda" date="1422529122"]
                  Is there a way to make the change directly from QtCreator ?
                  [/quote]
                  Not directly for this. You can read "this":http://qt-project.org/doc/qtcreator-3.0/creator-deploying-android.html#editing-manifest-files though, but for your problem you need to copy the manifest in the "ANDROID folder":http://doc.qt.io/qt-5/platform-notes-android.html then it will be copied and deployed when creating the apk file.

                  --- 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
                  0
                  • L Offline
                    L Offline
                    lambda
                    wrote on last edited by
                    #9

                    I proceed using Qt Creator 3.3.0 ( the interface is slightly different than shown on the document).

                    • The case 'Open package location after build' is checked in 'Advanced Actions' in the project settings.
                    • After building, a file explorer window is opened.
                    • I modify the AndroidManifest.xml adding:
                      <!-- Background running -->
                      <meta-data android:name="android.app.background_running" android:value="true"/>
                      <!-- Background running -->
                    • I launch the deployment, choosing an AVD.
                    • When the deployment is finished, I control the AndroidManifest.xml in the .apk with apktool and I found that the flag android.app.background_running is always set to false.
                      What is wrong in the proceeding ?
                    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