简体   繁体   English

当应用程序从Android上的任务管理器中被杀死时代码将停止运行

[英]Where will code stop running when app is killed from task manager on Android

If a user is running my app and decides to kill it via the task manager, are there any guarantees about how much code will be executed before the process dies? 如果用户正在运行我的应用程序并决定通过任务管理器将其终止,那么在进程终止之前是否有任何代码可以保证执行多少代码?

I feel like it could stop running at any arbitrary line, however I guess I don't really know the answer to this. 我觉得它可以停止在任意线上运行,但我想我真的不知道答案。

An example use case is for stopping and restarting a background alarm. 示例用例是用于停止和重新启动后台警报。 If I wanted to cancel an alarm, do some work, then reset the alarm, I feel like there is a chance that the app could stop running after the 'cancel alarm' step but before the 'reset alarm' step. 如果我想取消闹钟,做一些工作,然后重置闹钟,我觉得应用程序有可能在“取消闹钟”步骤之后但在“重置闹钟”步骤之前停止运行。 This would leave me in a state that I don't want to be in because I always want my alarm to be set to go off in the future. 这会让我处于一种我不想进入的状态,因为我总是希望将来我的闹钟能够启动。 (Keep in mind this is just an example, I'm not looking for workarounds to this specific case). (请记住,这只是一个例子,我不是在寻找这种特定情况的解决方法)。

Is there anything I can do to ensure that code my java code runs as a 'transaction' similar to a db transaction so that it either all runs or none of it runs? 我能做些什么来确保代码我的java代码作为类似于db事务的“事务”运行,以便它可以全部运行还是不运行?

If a user is running my app and decides to kill it via the task manager, are there any guarantees about how much code will be executed before the process dies? 如果用户正在运行我的应用程序并决定通过任务管理器将其终止,那么在进程终止之前是否有任何代码可以保证执行多少代码?

Not really. 并不是的。 If the user elects to use Force Stop in Settings, your process is terminated immediately with extreme prejudice. 如果用户选择在“设置”中使用“强制停止”,则会在极端偏见的情况下立即终止您的过程。 In other situations where your process is terminated, Android usually will destroy outstanding activities and services, but that is not guaranteed either, particularly if Android is in a rush to free up system RAM (eg, to handle an incoming phone call). 在您的流程终止的其他情况下,Android 通常会破坏未完成的活动和服务,但这也不能保证,特别是如果Android急于释放系统RAM(例如,处理来电)。 Removing the task from the overview screen is not really distinctive here. 从概览屏幕中删除任务在这里并不是很有特色。

Is there anything I can do to ensure that code my java code runs as a 'transaction' similar to a db transaction so that it either all runs or none of it runs? 我能做些什么来确保代码我的java代码作为类似于db事务的“事务”运行,以便它可以全部运行还是不运行?

No. 没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android如何在用户杀死应用程序后继续运行后台服务? - Android How to keep Running the background service when app is killed by user? 当我从任务管理器中刷出应用程序时,在单独进程中运行的Android服务会终止 - Android service running in separately process kills when i swipe out application from task manager 应用程序被任务管理器杀死后,该服务是否仍然可以运行? - Is it possible that the service still runs after the app got killed with task manager? 应用程序被杀死时如何停止接收通知? - How to stop receiving notifications when app is killed? Android:当应用程序被杀死时从服务启动活动 - Android: Start an Activity from a Service when app is killed “杀死”后在后台运行Android应用程序 - Running Android App in the Background after “killed” Android-取消并重新启动应用程序后,偏好设置无法保存吗? - Android - preferences not saving when app is killed and restarted? Android:防止应用被杀死 - Android: Prevent app from being killed android模拟器内存​​选项阻止我的应用程序运行 - android emulator memory options stop my app from running Android-应该在未运行任务的情况下 - Android - Task is not running when it should
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM