android 意图:动作什么时候可以为空?

android intent: when can the action be null?

在一个已经存在的项目中,我看到服务检查意图是否为空以及意图操作是否为空。

我知道如果服务被调用为:

context.startService(new Intent(context, MyService.class));

但我不知道框架是否有这样的调用。

系统是否曾使用空意图操作启动服务?

服务是否可能以空意图启动?

Does the system ever start a service with a null intent action?

当然可以。这称为显式 Intent,您可以在其中标识要启动的特定组件。这是您应该用于自己的私人活动、服务等的 Intent

Is it possible that a service is started with null intent?

服务总是创建 使用非null Intent。但是,如果由于 Android 由于内存不足而终止进程而重新创建服务,则可以使用 null Intent 调用 onStartCommand(),其中较早的进程' 服务实例从其 onStartCommand().

返回 START_STICKY