NativeScript / NativeScript/android
App killed when starting a foreground activity on some devices
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 563
- 派生
- 144
- 平均合并
- 10 小时 46 分钟
- 30 天内合并 PR
- 14
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 NativeScript 相机演示开始,在受影响的 Huawei Mediapad T5 上复现生命周期。启动相机或 Android PrintManager 时,跟踪 activityDestroyed 和 NativeScript 退出事件,然后将结果与预期行为进行比较:启动前台 activity 后,NativeScript activity 仍保持可用。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android
- 领域
- mobile
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 30/100