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 Service goes to sleep when phone locked

Android Service goes to sleep when phone locked

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

    Hi all,

    I have very strange problem. I have created app which uses Android Service. Service is reporting to external application via TCP every minute. Everything works as long as I have USB cable (with debug) attached to the phone. When I disconnect debug cable Android Service goes to sleep after a few seconds.

    Service uses QTimer to report updates to external app every minute, and when service goes to sleep network connection is still active, just QTimer inside Android Service doesn't count. I am not an expert but it looks like main event loop inside Service just stops.

    To illustrate the problem I have prepared small example, I know I should paste it here, but there are to many files, including gradle-wrapper.jar (I was following this example qt-android-create-android-service-using-qt/ so my example is here

    It counts seconds, first count is from QTimer inside Android Service, second is QTime difference between time saved inside Service and current QTime when reporting QTimer timeout, they should be the same but if you lock the phone they aren't after some 20 seconds.

    Can someone confirm that ? Is there something wrong with what I'm doing?

    Best Regards
    Marek

    ekkescornerE 1 Reply Last reply
    0
    • M Offline
      M Offline
      Marek
      wrote on last edited by
      #2

      Some more detaiils, I'm using Qt 5.7.0 on Linux, phone is Samsung Galaxy S3 with Android 4.2.2

      1 Reply Last reply
      0
      • M Marek

        Hi all,

        I have very strange problem. I have created app which uses Android Service. Service is reporting to external application via TCP every minute. Everything works as long as I have USB cable (with debug) attached to the phone. When I disconnect debug cable Android Service goes to sleep after a few seconds.

        Service uses QTimer to report updates to external app every minute, and when service goes to sleep network connection is still active, just QTimer inside Android Service doesn't count. I am not an expert but it looks like main event loop inside Service just stops.

        To illustrate the problem I have prepared small example, I know I should paste it here, but there are to many files, including gradle-wrapper.jar (I was following this example qt-android-create-android-service-using-qt/ so my example is here

        It counts seconds, first count is from QTimer inside Android Service, second is QTime difference between time saved inside Service and current QTime when reporting QTimer timeout, they should be the same but if you lock the phone they aren't after some 20 seconds.

        Can someone confirm that ? Is there something wrong with what I'm doing?

        Best Regards
        Marek

        ekkescornerE Offline
        ekkescornerE Offline
        ekkescorner
        Qt Champions 2016
        wrote on last edited by
        #3

        @Marek please provide your example as github repo

        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
        5.15 --> 6.9 https://t1p.de/ekkeChecklist
        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marek
          wrote on last edited by
          #4

          Hi

          Github repo here

          Best Regards
          Marek

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Marek
            wrote on last edited by
            #5

            Hi all,

            Can someone offer any help on this. I mean how should I proceed.
            Is this a bug and file the report, or have I done something wrong?

            Best Regards
            Marek

            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