假设我们以以下方式启动服务。
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);
当我们使用意图停止服务时,是否必须使额外数据与先前的意图相同?
没有多余的内容不用于标识作为Intent
目的地的组件。
如果我们使用不同的额外数据创建一个Intent,将停止先前启动的服务吗?
是的,尽管额外功能在这种情况下是没有用的-我认为该服务无法访问它们。因此,如果方便的话,您可以跳过添加这些额外功能的代码。