cordova-android
cordova-android copied to clipboard
Cannot resume the app after hiding with lounchMode "singleInstance" or "single Top"
Bug Report
Problem
Hallo guys! I found some problem.. maybe anyone can help.
with android “singleInstance” or “singleTop” after onPause my app was killed from system tasks. and then if I switched to the app again cordova do app restart…. How I can fix this?
tested on:
Huawei P20 Pro-onRESUMEeventnotfiredNexus 5X-onRESUMEeventalwaysfired
What is expected to happen?
back to the app and not restart the app after opening
What does actually happen?
2021-01-18 14:54:51.184 22311-22311/com.example.myapp D/CordovaActivity: Paused the activity.
2021-01-18 14:54:51.195 22311-22311/com.example.myapp I/chromium: [INFO:CONSOLE(4)] "FIRE -> onDevicePause -> device paused", source: file:///android_asset/www/js/app.min.js (4)
2021-01-18 14:54:51.418 22311-22348/com.example.myapp D/ZrHung.AppEyeUiProbe: not watching, wait.
2021-01-18 14:54:51.648 22311-22349/com.example.myapp W/libEGL: EGLNativeWindowType 0x7524822950 disconnect failed
2021-01-18 14:54:51.657 22311-22349/com.example.myapp W/libEGL: EGLNativeWindowType 0x7524822d10 disconnect failed
2021-01-18 14:54:52.130 22311-22311/com.example.myapp D/CordovaActivity: Stopped the activity.
2021-01-18 14:54:52.159 22311-22311/com.example.myapp D/CordovaActivity: CordovaActivity.onDestroy()
2021-01-18 14:54:52.160 22311-22311/com.example.myapp D/CordovaWebViewImpl: >>> loadUrl(about:blank)
2021-01-18 14:54:52.170 22311-22311/com.example.myapp W/cr_AwContents: WebView.destroy() called while WebView is still attached to window.
2021-01-18 14:54:52.179 22311-22311/com.example.myapp D/ActivityThread: Remove activity client record, r= ActivityRecord{de81ed2 token=android.os.BinderProxy@88805e7 {com.example.myapp/com.example.myapp.MainActivity}} token= android.os.BinderProxy@88805e7
2021-01-18 14:54:52.188 22311-22311/com.example.myapp W/cr_AwContents: Application attempted to call on a destroyed WebView
java.lang.Throwable
at org.chromium.android_webview.AwContents.p(chromium-TrichromeWebViewGoogle.aab-stable-428014133:2)
at vM.loadingStateChanged(chromium-TrichromeWebViewGoogle.aab-stable-428014133:2)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:363)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Information
$ cordova -v
10.0.0
$ cordova platform ls
Installed platforms:
android 9.0.0
ios 6.1.1
$ cordova plugin ls
com.lampa.startapp 6.1.6 "startApp"
cordova-clipboard 1.3.0 "Clipboard"
cordova-plugin-android-fingerprint-auth 1.5.0 "FingerprintAuth"
cordova-plugin-android-permissions 1.1.2 "Permissions"
cordova-plugin-androidx-adapter 1.1.3 "cordova-plugin-androidx-adapter"
cordova-plugin-apprate 1.7.1 "AppRate"
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-camera 5.0.1 "Camera"
cordova-plugin-ckopenimage 1.2.0 "cordova-plugin-ckopenimage"
cordova-plugin-customurlscheme 5.0.2 "Custom URL scheme"
cordova-plugin-deeplinks 1.1.1 "Cordova Deeplinks Plugin"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-document-viewer 1.0.0 "SitewaertsDocumentViewer"
cordova-plugin-file-opener2 3.0.5 "File Opener2"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-ignore-lint-translation 0.0.1 "cordova-plugin-ignore-lint-translation"
cordova-plugin-inappbrowser 4.1.0 "InAppBrowser"
cordova-plugin-ios-keychain 3.0.1 "KeyChain Plugin for Cordova iOS"
cordova-plugin-nativestorage 2.3.2 "NativeStorage"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-safariviewcontroller 1.6.0 "SafariViewController"
cordova-plugin-splashscreen 6.0.0 "Splashscreen"
cordova-plugin-touch-id 3.3.1 "Touch ID"
cordova-plugin-whitelist 1.3.4 "Whitelist"
Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Maybe Related to https://github.com/apache/cordova-android/issues/1000
Update: its looks like that cordova or android completely destroy connection to the app.
on Nexus connection to dev-tools stay always opened. on Huawei after click on on home-button connections will be emmidiately destroyed.
I actually noticed the same thing on a handful of different simulator tests with different versions of cordova-android (11 and 12).
Were you ever able to figure out how to get the app to not be destroyed when you send it to the background?
There is no way to prevent the app from being destroyed when it's entering the background.
The OS may destroy the app activity for several reasons. If the app is in the foreground those reasons are limited, but it's far more likely for the OS to destroy the app once the app goes in the background.
If the activity onDestroy is called (as shown in the OP stacktrace) it means the OS has decided to destroy the app. More information on the android life cycle can be read here.
Note that natively there are ways to serialize/store view state so that it can be recreated later during the Create life-cycle, however as far as I know, there is no way to serialize webview state. It is rather large issue with all webview-based applications.
There is no way to prevent the app from being destroyed when it's entering the background.
The OS may destroy the app activity for several reasons. If the app is in the foreground those reasons are limited, but it's far more likely for the OS to destroy the app once the app goes in the background.
If the activity
onDestroyis called (as shown in the OP stacktrace) it means the OS has decided to destroy the app. More information on the android life cycle can be read here.Note that natively there are ways to serialize/store view state so that it can be recreated later during the
Createlife-cycle, however as far as I know, there is no way to serialize webview state. It is rather large issue with all webview-based applications.
Thanks. That's too bad. I can see the OnPause being triggered but then some destroy event is also being triggered afterwards. I'll take a look at the idea of saving the state.