有什么方法可以保证Onpause或Onstop Android生命周期事件直到最后?
在 android文档,至少,至少,至少,至少,至少, Onpause
无法杀死。也许我的解释是不正确的,但我知道它总是会直到最后。我已经进行了多个测试,并进行了一个漫长的循环周期,可以中断它的一半呼叫。
我想在呼叫中保存一些持久数据,但不幸的是,它可以中途中断。我知道我应该优化它,并且要做,但是我想保证我使用的生命周期电话会运行到最后。
In the Android documentation, it's stated that, at least, onPause
is not killable. Maybe my interpretation is incorrect but I understood that it would always run until the end. I've made several tests with a lengthy loop cycle and I can interrupt it half call.
I want to save some persistent data in the call but unfortunately, it can be interrupted halfway through. I'm aware I should optimize it and I'm going to do it but I wanted to guarantee that the lifecycle call I'm using would run until the end.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将这些事件提出来“制动”它们的唯一方法是在结束前提出例外。
说“ onpause/onStop事件不是可杀死的”仅表示下面的代码(伪代码)将始终执行您的代码:
但是,Android文档说,在这些方法之后,这些方法可以是在任何时候,在任何情况下,在任何情况下都将执行Onpause/Onstop事件,无论如何在任何情况下都将被杀死。
如果您想安全地保存这些异步事件的持久数据,我建议您产生不同的过程,然后传递“序列化”(使用AIDL?)对象。遗忘了这个新的过程仅保留给这种执行。
If those events are raised the only way to "brake" them is by throwing an Exception before their end.
Saying that "onPause/onStop events are not killable" only means that this below code (pseudo-code) will always execute YOUR CODE:
However Android Docs says that AFTER these methods the Process could be killed in any time, but the onPause/onStop events will be executed from their begin to their end in any case.
If you want to be secure to save persistant data on those ASYNC events, I suggest you to spawn a different Process and pass "serialized" (using AIDL?) objects to it. Obliviously this spawned new Process is reserved to only this kind of execution.