NativeScript / NativeScript/android

App killed when starting a foreground activity on some devices

Ouverte
#1,605 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
C++
Étoiles
563
Forks
144
Merge moyen
10 h 46 min
PR mergées (30 j)
14

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez avec la démo de caméra NativeScript et reproduisez le cycle de vie sur un Huawei Mediapad T5 affecté. Suivez les événements activityDestroyed et de sortie de NativeScript lors du lancement de la caméra ou d’Android PrintManager, puis comparez le résultat avec le comportement attendu selon lequel l’activité NativeScript reste utilisable après le démarrage d’une activité au premier plan.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
android
Domaine
mobile
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.