Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-55846

Android app hangs (ANR) on exit when using service

    XMLWordPrintable

Details

    • Android
    • 2022wk40FOQtforAndroid, 2022wk42FOQtforAndroid, 2022wk44FOQtforAndroid, 2022wk46FOQtforAndroid, 2022wk50FOQtforAndroid, 2022wk52FOQtforAndroid, 2023wkXXFOQtforAndroid

    Description

      I'm trying to create Qt app which would use OneSignal SDK for implementing Push notifications.

      Everything kinda works (using JNI of course), but there is issue that if OneSgnal is setup correctly, app does not exit properly when is swiped-away in Android app list view. Though main window disappears, logcat shows that Android is still waiting for it to close (see attached full logcat.txt log since app close):

      09-07 11:29:42.656  1522  1536 W ActivityManager: Activity destroy timeout for ActivityRecord{665b4d3 u0 com.QtOneSignalExample/org.qtproject.qt5.android.bindings.QtActivity t17 f}
      

      After 20 seconds of attempted close, /data/anr/traces.txt has dumped interesting output, with Qt stack printed (see attached traces.txt for full traces):

      "main" prio=5 tid=1 Native
        | group="main" sCount=1 dsCount=0 obj=0x7459d258 self=0xb40f4500
        | sysTid=2608 nice=0 cgrp=default sched=0/0 handle=0xb77eec00
        | state=S schedstat=( 0 0 0 ) utm=8 stm=3 core=0 HZ=100
        | stack=0xbf2ba000-0xbf2bc000 stackSize=8MB
        | held mutexes=
        kernel: futex_wait_queue_me+0xcd/0x113
        kernel: futex_wait+0xc5/0x197
        kernel: do_futex+0x9b/0x742
        kernel: SyS_futex+0xaf/0xf6
        kernel: syscall_call+0x7/0xb
        native: #00 pc 000171e0  /system/lib/libc.so (syscall+32)
        native: #01 pc 000276f1  /system/lib/libc.so (sem_wait+169)
        native: #02 pc 0001ab13  /data/data/com.QtOneSignalExample/qt-reserved-files/plugins/platforms/android/libqtforandroid.so (???)
        native: #03 pc 005f874e  /data/app/com.QtOneSignalExample-2/oat/x86/base.odex (void org.qtproject.qt5.android.QtNative.terminateQt()+98)
        native: #04 pc 005e1324  /data/app/com.QtOneSignalExample-2/oat/x86/base.odex (void org.qtproject.qt5.android.QtActivityDelegate.onDestroy()+120)
        native: #05 pc 00137a82  /system/lib/libart.so (art_quick_invoke_stub+338)
        native: #06 pc 001435c4  /system/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+212)
        native: #07 pc 0050f858  /system/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned int)+1736)
        native: #08 pc 0048c5e3  /system/lib/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobject*)+80)
        native: #09 pc 00314ca4  /data/dalvik-cache/x86/system@framework@boot.oat (???)
        at org.qtproject.qt5.android.QtNative.terminateQt(Native method)
        at org.qtproject.qt5.android.QtActivityDelegate.onDestroy(QtActivityDelegate.java:972)
        at java.lang.reflect.Method.invoke!(Native method)
        at org.qtproject.qt5.android.bindings.QtApplication.invokeDelegateMethod(QtApplication.java:153)
        at org.qtproject.qt5.android.bindings.QtApplication.invokeDelegate(QtApplication.java:142)
        at org.qtproject.qt5.android.bindings.QtActivity.onDestroy(QtActivity.java:1033)
        at android.app.Activity.performDestroy(Activity.java:6407)
        at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
        at android.app.ActivityThread.-wrap5(ActivityThread.java:-1)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke!(Native method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
      

      If I close app and then start new instance within 20 seconds after close (while last instances is hanging), it is displayed frozen on initial screen, and after some time Android displays dialog to either wait more or close the app. After initial app is killed, I can start new instance without problem, and the new cycle begins.

      I have attached fully working example, only valid OneSignal APP ID and Google Project Number must be entered into AndroidManifest.xml (see here how to setup. OneSignal accounts are free). One can send Push notifications from OneSignal dashboard, but that's irrelevant for reproducing this bug.

      If OneSignal.init() is not called (within PushNotificationmManager.java), or app id is invalid, there is no problem. Also, official OneSignal Java example works OK (closing and opening again works fine, no freezing), problem exist only when using within Qt app. I have also created OneSignal issue, as I am not quite sure where's the actual problem.

      Attachments

        1. logcat.txt
          10 kB
        2. QtOneSignalExample.zip
          6.70 MB
        3. traces.txt
          279 kB

        Issue Links

          Activity

            People

              qtandroidteam Qt Android Team
              talkless Vincas Dargis
              Votes:
              13 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

                Created:
                Updated: