App killed when starting a foreground activity on some devices

Offen
#1,605 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
30/100
Issue-Typ
Bug
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
android
Bereich
mobile

Rechercherichtung

Beginnen Sie mit der NativeScript-Kamerademo und reproduzieren Sie den Lebenszyklus auf einem betroffenen Huawei Mediapad T5. Verfolgen Sie die activityDestroyed- und NativeScript-exit-Ereignisse, während Sie die Kamera oder den Android PrintManager starten, und vergleichen Sie das Ergebnis mit dem erwarteten Verhalten, dass die NativeScript-Aktivität nach dem Starten einer Vordergrundaktivität weiterhin verwendbar bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 6.5.0
  • Cross-platform modules: 6.5.1
  • Android Runtime: 6.4.1
  • Plugin(s):
    @nstudio/nativescript-checkbox
    nativescript-bitmap-factory": "^1.8.1",
    nativescript-bluetooth
    nativescript-camera
    nativescript-drawingpad
    nativescript-feedback
    nativescript-fonticon
    nativescript-geolocation
    nativescript-iqkeyboardmanager
    nativescript-localize
    nativescript-modal-datetimepicker
    nativescript-print-zebra
    nativescript-printer
    nativescript-sqlite
    nativescript-sqlite-commercial
    nativescript-sqlite-encrypted
    nativescript-toasty
    nativescript-zip

Describe the bug
On some devices, at least on Huawei Mediapad T5, when I start a new activity that goes on the foreground, the NativeScript activity gets killed. When I go back, the NS activity restarts.
After some investigation, I concluded that it's a battery management issue. Android always kills app activities put in the background to minimize battery usage, but on some devices (mainly Huawei from what I've found) this mechanism is very aggressive and kills the activity immediately after it goes in the background. The Android activityDestroyed event and NS exit event are not called.

I have two scenarios:

  • Opening the camera with nativescript-camera plugin. The NS activity is killed but the camera still works, allowing me to retrieve the photo uri on restart.
  • Printing with the system service PrintManager. In this case, when the NS activity is killed the print tool closes too. To the user, it looks like a crash.

My goal is to prevent the perceived crash at least on the second scenario. Is there a way to release enough resources when the activity is paused?

Allowing the app to ignore battery optimization and managing manually launch/app launch doesn't solve the issue.

To Reproduce
Launch the nativescript-camera demo on an affected device.

Expected behavior
The NS activity is not killed after it starts a new activity.

Vorherrschende Sprache
C++
Sterne
563
Forks
144
Ø Merge
10 Std. 46 Min.
Gemergte PRs (30 T.)
14

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NativeScript/android

Alle Issues in NativeScript/android

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.