安卓:国家杀害力的应用程序 [英] Android: State of force killed applications

查看:144
本文介绍了安卓:国家杀害力的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我可以看书,安卓可能会杀死我的过程中随时的 1

有人可能会跨preT的文章[1],这样,在任何时候,进程必须能够崩溃生存。这是怎么处理的?被称为中的任何方法有什么保证,如果一个进程被杀死这种方式?文章*没有提到它。

我的问题是,你怎么保证一个强制杀死进程恢复在下次启动时一些理智的方式吗?唯一的国家我的过程(假设无担保的方法被调用时,进程被终止由)是持久存储状态(一个数据库或其他地方),这很可能是不完整的,如果过程是强制杀死。

具体的例子:比方说,我问一个服务来执行一些工作。这项工作是不是喜欢玩音乐文件。它是一个可以被认为是完成在某些点(例如,发送数据到web)的工作。如果我的服务被打死,说工作的50%,完成后,如何将我的应用程序知道的工作是成功的?我可以在持久存储一个标志说:完成,但即使这样,机器人可能会杀了我的服务之后,我把最后一个字节之前,我设置标志。

有没有处理这个任何常见的方式?我的服务能,重新启动时,谈判与Web服务器来查看该文件被转移,但很快变得非常复杂,我不认为这将真正解决问题。

我知道以下文本[1],但没有解决对服务的问题,这最后状态在每次用户离开该应用程序的该部分产生的,而不是当它被杀死​​

我发现了一些很有趣的。一个明显的不一致Android的文档与此相关的研究。请参阅我的新问题<一href="http://stackoverflow.com/questions/23801934/android-inconsistency-in-documentation-when-may-an-app-be-killed">2

在明显不一致已得到解决。这是因为我不是precise关于应用程序/程序/活动条款。这个问题仍然有效,但。

解决方案
  

现被称为如果一个进程被杀死这种方式中的任何方法有什么保证?

没有叫上你的应用程序时,你的进程被终止。

  

你怎么保证一个强制杀死进程恢复在下次启动时一些理智的方式?

这不能回答是抽象的。

  

的唯一国家我的过程(假设没有保证能够在被调用时,进程被杀死的方法制成)是永久存储的状态(DB或其他地方),这很可能是不完整的,如果过程是力杀害。

您应该更新您的本地持久存储时,数据的变化。因此,你的持久化存储可能是最新的,当你的进程被终止。一个内存缓存应该被视为一个读缓存,而不是写缓存。

  

有一个可以考虑在某一时刻完成的(例如,将数据发送到web)的工作。如果我的服务被打死,说工作的50%,完成后,如何将我的应用程序知道的工作是成功的?

它必须与Web服务器进行谈判,以确定发生了什么,并没有上传成功。

  

有没有处理这个任何常用的方法?

有各种方法试图保持事务的完整性,特别是对于长时间运行的操作,其中进程终止提出了一个更大的问题。这些都不是独一无二的机器人,因为这一直是一个问题在计算机数十年。大部分归结为检查什么成功,并重新尝试什么都没有。如何复杂,这是你正在努力更新数据,并更新其现有手段的性质完全取决于

As far as I can read, Android may kill my process at any time 1.

One might interpret the article [1] such that, at any point, a process must be able to survive a crash. How is that handled? Are there any guarantees of any methods being called if a process is killed this way? The article* doesn't mention it.

My question is, how do you guarantee that a force-killed process resumes in some sane way on next start? The only state my process has (assuming no guarantees are made for methods being called when process is killed) is the state in persistent storage (a DB or elsewhere) and this is likely to be incomplete if process is force-killed.

Concrete example: Let's say I ask a Service to perform some work. This work is not something like playing a music file. It is work that can be considered "done" at some point (e.g. sending data to the web). If my Service gets killed, say after 50% of the work is done, how would my app know if the work was successful? I could have a flag in persistent storage saying "done", but even then, Android might kill my Service after I send the last byte and before I set the flag.

Is there any common way of handling this? My Service could, when restarted, negotiate with the web server to see if the file was transferred, but it quickly gets really complicated and I don't think it would really solve the problem.

[Edit 1 start]

I am aware of the following text [1] but that does not solve the problem for services, "This last state is generated each time the user leaves that part of the application, not when it is killed"

[Edit 1 end]

[Edit 2 start]

I found something really interesting. An apparent inconsistency in the Android documentation related to this. Please see my new question at 2

[Edit 2 end]

[Edit 3 start]

The "apparent inconsistency" has been resolved. It was due to me not being precise about "app"/"process"/"activity" terms. This question still stands, though.

[Edit 3 end]

解决方案

Are there any guarantees of any methods being called if a process is killed this way?

Nothing is called on your app when your process is terminated.

how do you guarantee that a force-killed process resumes in some sane way on next start?

That cannot be answered in the abstract.

The only state my process has (assuming no guarantees are made for methods being called when process is killed) is the state in persistent storage (a DB or elsewhere) and this is likely to be incomplete if process is force-killed.

You should be updating your local persistent store when the data changes. Hence, your persistent store is likely to be up to date when your process is terminated. An in-memory cache should be treated as a read cache, not a write cache.

It is work that can be considered "done" at some point (e.g. sending data to the web). If my Service gets killed, say after 50% of the work is done, how would my app know if the work was successful?

It would have to negotiate with the Web server to determine what was and was not successfully uploaded.

Is there any common way of handling this?

There are various approaches for trying to maintain "transactional integrity", particularly for long-running operations where process termination poses a greater issue. None of those are unique to Android, as this has been a problem in computers for decades. Most boil down to "check what succeeded, and re-try what didn't". How complicated this is depends entirely on the nature of the data you are trying to update and the available means for updating it.

这篇关于安卓:国家杀害力的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆