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. Notification Of Android App Being Resumed In A New Process After Closure By User?
Forum Updated to NodeBB v4.3 + New Features

Notification Of Android App Being Resumed In A New Process After Closure By User?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 4 Posters 837 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.
  • KenAppleby 0K Offline
    KenAppleby 0K Offline
    KenAppleby 0
    wrote on last edited by KenAppleby 0
    #1

    Qt6.4 NDK 31

    I am developing an android app which needs to receive certain types of files from other apps via the a VIEW Action in the android Activity-Intent-Action mechanism as specified in the AndroidManifest.xml.

    This all works fine, except for the case when the app has been closed by the user and needs to be resumed.

    When an android app is closed by the user its process may be killed by the OS. This is visible in the output of logcat in Android Studio. In this case, when the VIEW Intent is passed to the Java code defined in the app, the OS has resumed the app in a new process, as can be seen in the logcat output, but the app has not been entered through main(). It's as if the app has been kept in its previous state and bound to a new process rather than being restarted.

    This causes a problem if you are using native function calls, because the native function calls are not registered in the Java Environment of the new process. It is not possible to make native function calls from the Java Activity code handling the Intent.

    This could be handled, for instance, if there were notifications from the QApplication when the app is resumed. But I can find no mention of such notifications or events.

    I am new to android programming so it may well be that I have misunderstood how this stopping and restarting of apps works in conjunction with Qt and the Java Environment on android .

    Any help would be gratefully received.

    ekkescornerE 1 Reply Last reply
    0
    • KenAppleby 0K KenAppleby 0

      Qt6.4 NDK 31

      I am developing an android app which needs to receive certain types of files from other apps via the a VIEW Action in the android Activity-Intent-Action mechanism as specified in the AndroidManifest.xml.

      This all works fine, except for the case when the app has been closed by the user and needs to be resumed.

      When an android app is closed by the user its process may be killed by the OS. This is visible in the output of logcat in Android Studio. In this case, when the VIEW Intent is passed to the Java code defined in the app, the OS has resumed the app in a new process, as can be seen in the logcat output, but the app has not been entered through main(). It's as if the app has been kept in its previous state and bound to a new process rather than being restarted.

      This causes a problem if you are using native function calls, because the native function calls are not registered in the Java Environment of the new process. It is not possible to make native function calls from the Java Activity code handling the Intent.

      This could be handled, for instance, if there were notifications from the QApplication when the app is resumed. But I can find no mention of such notifications or events.

      I am new to android programming so it may well be that I have misunderstood how this stopping and restarting of apps works in conjunction with Qt and the Java Environment on android .

      Any help would be gratefully received.

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

      @KenAppleby-0 perhaps it helps to set

      android:launchMode="singleInstance"
      

      in Manifest.

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

        Interesting suggestion, thanks.
        But the behaviour is the same. The Intent is executed in a new process and the java enviroment is gone, or at least not initialised with the native calls.
        Ken

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          is it possible to restart your app?
          https://www.kdab.com/qt-on-android-how-to-restart-your-application/

          KenAppleby 0K 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            is it possible to restart your app?
            https://www.kdab.com/qt-on-android-how-to-restart-your-application/

            KenAppleby 0K Offline
            KenAppleby 0K Offline
            KenAppleby 0
            wrote on last edited by KenAppleby 0
            #5

            @JoeCFD Thank you for the link. Yes, restarting the app is what I am in fact doing. But it has to be done from Java. We're in the onCreate() method of a custom Activity handling a VIEW Intent. When the app is open it is possible to call the native functions and pass the necessary information up to the Qt code. But when the app has been closed and then reopened by the OS to handle the Activity the native functions are no longer registered in the new java environment.

            So I am using getPackageManager().getLaunchIntentForPackage() and starting that, having Bundled the data into the launch Intent.

            This works, but I wonder whether this is a valid Android thing to do. Is it going to lead to problems? It certainly will lead to non-standard behaviour because app state, what the user was doing when the app was closed, is lost. The Qt code is reentered from main(), the application's QMainWindow and all children are recreated. All application state previously held in the Qt objects is gone. This means that the app will behave differently from when it is reopened by the user from the desktop.

            It is very useful that Android preserves the state of an app when it is closed, so that when it is reopened it can resume from where it left off. But the state appears not to include the Java Interface Function Table.

            I have noticed that when restarted by the launch Activity the app runs in the same process as the one that was reopened by the OS in response to the first Activity: the pid is the same prior to and after the launch Intent. Can I just assume that Android handles this reconstruction of the task?

            An asynchronous way, via a signal for instance, of detecting from Qt code that the app has been restarted in a new process with a new Jenv would be helpful.

            However, as I said earlier, I am fairly new to Android and could well be misunderstanding what is going on. Perhaps there are application settings in the manifest that can help?

            V 1 Reply Last reply
            0
            • KenAppleby 0K KenAppleby 0

              @JoeCFD Thank you for the link. Yes, restarting the app is what I am in fact doing. But it has to be done from Java. We're in the onCreate() method of a custom Activity handling a VIEW Intent. When the app is open it is possible to call the native functions and pass the necessary information up to the Qt code. But when the app has been closed and then reopened by the OS to handle the Activity the native functions are no longer registered in the new java environment.

              So I am using getPackageManager().getLaunchIntentForPackage() and starting that, having Bundled the data into the launch Intent.

              This works, but I wonder whether this is a valid Android thing to do. Is it going to lead to problems? It certainly will lead to non-standard behaviour because app state, what the user was doing when the app was closed, is lost. The Qt code is reentered from main(), the application's QMainWindow and all children are recreated. All application state previously held in the Qt objects is gone. This means that the app will behave differently from when it is reopened by the user from the desktop.

              It is very useful that Android preserves the state of an app when it is closed, so that when it is reopened it can resume from where it left off. But the state appears not to include the Java Interface Function Table.

              I have noticed that when restarted by the launch Activity the app runs in the same process as the one that was reopened by the OS in response to the first Activity: the pid is the same prior to and after the launch Intent. Can I just assume that Android handles this reconstruction of the task?

              An asynchronous way, via a signal for instance, of detecting from Qt code that the app has been restarted in a new process with a new Jenv would be helpful.

              However, as I said earlier, I am fairly new to Android and could well be misunderstanding what is going on. Perhaps there are application settings in the manifest that can help?

              V Offline
              V Offline
              Vlad998
              wrote on last edited by
              #6

              @KenAppleby-0 Could you show a working example?

              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