如果没有第三行代码, Intent 将是隐式的。设置包是否使其明确?该组件未指定,因此基于 Stack Overflow answers :这是隐含的...
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage("com.example.app");
startActivity(intent);
...但是提供了目标应用程序的包名称,因此它是明确的,基于 docs :
Explicit intents specify which application will satisfy the intent, by supplying either the target app's package name or a fully-qualified component class name.
最佳答案
显式意味着定义的应用程序(也称为包)应该处理 Intent 。
当您设置应该处理 Intent 的包时,是的,它使它变得明确。
添加
我选择definition of explicit考虑在内,这意味着操作已定义。
fully and clearly expressed or demonstrated; leaving nothing merely implied; unequivocal:
然后如果检查setPackage
docs它说
(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.
因此,关键在于如何理解术语隐式
和显式
。
对我来说(根据我对 android 文档的理解),隐式是
Hey, I want to share this awesome image, lets give it to the world
这将打开 facebook、instagram、whatsapp 等的选择器。
显式的是
Hey, I want to share this awesome image with Instagram, open it and share the image please
仅打开 Instagram(按包)。
关于android - 设置包名称是否会使隐式 Intent 显式化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54538924/