START_STICKY和START_REDELIVER_INTENT之间的区别?区别、START_STICKY、START_REDELIVER_INTENT

2023-09-08 10:04:11 作者:我是小草莓

我为我的Andr​​oid应用程序创建一个服务,通过向意图服务提供的数据。问题是,当服务由系统不是提供给它的意图破坏的数据无法恢复,其结果是我的应用程序崩溃。

I am creating a service for my android app, providing data to the service via Intents. The problem is that when the service is destroyed by the system than the intent data provided to it can't be restored, as a result of which my app crashes.

我听过 START_REDELIVER_INTENT 将尽快有足够的可用内存恢复提供服务,而 START_STICKY 将无法恢复数据的意图。

I have heard START_REDELIVER_INTENT will restart my service as soon as there is sufficient memory available restoring the intent data provided to service whereas the START_STICKY will not restore the intent data.

是吗?或者是有什么我不知道?

am i right ? or is there something I don't know ?

另外我的服务正在永远它是由系统破坏后重新启动。

Also my service is taking forever to restart after it is destroyed by the system.

推荐答案

START_STICKY - 它会告诉系统创建服务,当可用内存足以做一个最新副本,后保持状态,并从低内存恢复。在这个过程中,我们将失去,可能以前的计算结果。

START_STICKY- It will tell the system to create a newest copy of the service, when available memory is sufficient to do, after it retains state and recovers from the low memory. In this process we will loose the results that might have calculated before.

START_REDELIVER_INTENT - 它会告诉系统重新启动和崩溃后恢复服务,并重新提交该是present在崩溃时的意图发生

START_REDELIVER_INTENT- It will tell the system to restart and regain the service after the crash and also redeliver the intents that were present at the time of crash happened.

这旁边,我们还可以对 START_NOT_STICKY

beside this we can have also a little note about START_NOT_STICKY

START_NOT_STICKY - 它会告诉系统不用担心,操心重新启动该服务,即使是有足够的可用内存

START_NOT_STICKY- It will tell the system not to worry and bother about to restart the service, even when it is having sufficient available memory.

请访问更多

http://developer.android.com/reference/android/app/Service.html