当我们使用意图停止服务时,是否必须使多余的数据与先前的意图相同?

问题描述 投票:1回答:1

假设我们以以下方式启动服务。

启动服务

Intent intent = new Intent(this, X.class);
intent.putExtra(X.TOKEN, "ABC");
startService(intent);

如果我们使用不同的额外数据创建一个Intent,将停止先前启动的服务吗?

Intent intent = new Intent(this, X.class);
intent.putExtra(X.TOKEN, "DEF");
// Will this stop the previous started service?
stopService(intent);
android
1个回答
0
投票

当我们使用意图停止服务时,是否必须使额外数据与先前的意图相同?

没有多余的内容不用于标识作为Intent目的地的组件。

如果我们使用不同的额外数据创建一个Intent,将停止先前启动的服务吗?

是的,尽管额外功能在这种情况下是没有用的-我认为该服务无法访问它们。因此,如果方便的话,您可以跳过添加这些额外功能的代码。

© www.soinside.com 2019 - 2024. All rights reserved.