如果机器人重新启动某个服务的onCreate再次叫什么名字?重新启动、叫什么名字、机器人、onCreate

2023-09-07 08:37:34 作者:浮云先生ヾ

这是我的小机器人的知识,我明白,Android操作系统在极端内存不足的情况​​下,杀了我的服务。

From my little android knowledge I understand that android OS can kill my service under extreme memory conditions.

我已经创建了一个返回 START_STICKY 的服务。该服务是为了在后台运行。

I have created a service that returns START_STICKY. The service is meant to run in background.

如果Android是要杀死我的服务,将它称之为的onDestroy

If android is about to kill my service, will it call onDestroy ?

和重新启动时,将它称之为的onCreate

And when it restarts it would it call onCreate ?

推荐答案

看到这里,开发指南。 http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle

See here, the dev guide. http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle

的onCreate()是当过程开始时只被调用,这既可以在第一时间服务正在运行,或者如果它被杀死在重新启动后,基本上这是每当启动称为

onCreate() is only called when the process starts, which can either be the first time the service is running, or if it was killed on restarted, essentially this is called whenever it starts.

onStartCommand()每当客户端调用叫做 startService()

onStartCommand() is called whenever a client calls startService().

当一个服务被销毁/完全停止,Android的应该叫的onDestroy()上的服务。我认为这是可能的,要不会发生(例如,过程不通过Android系统杀死)。在绑定服务的情况下,这是当没有更多的主动客户端的粘合剂

When a service is destroyed / completely stopped, Android is supposed to call onDestroy() on that service. I think it's possible for that to not happen (e.g. process is killed not through Android system). In the case of a bound service, this is when there are not more active client binders.

编辑:的onCreate()服务启动; onStartCommand()有人使用服务; 的onDestroy()服务被杀害/停止。

onCreate() Service starts; onStartCommand()someone uses service; onDestroy()Service is killed / stopped.