2

The intent would be implicit without the third line of code. Does setting the package make it explicit? The component isn't specified, so based on Stack Overflow answers: it is implicit...

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage("com.example.app");
startActivity(intent);

...but the target app's package name is supplied, so it is explicit, based on the 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.

Tamás Bolvári
  • 2,976
  • 6
  • 34
  • 57

1 Answers1

3

Explicit means that defined app (aka package) should handle the intent.

When you setup the package that should handle the intent, yes, it makes it explicit.

Addition

I take the definition of explicit into consideration, it means that action is defined.

fully and clearly expressed or demonstrated; leaving nothing merely implied; unequivocal:

Then if check the setPackage docs it says

(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.

So it's all about how to understand the terms Implicit and Explicit.

For me (and according what I understand from android docs), Implicit is

Hey, I want to share this awesome image, lets give it to the world

Which opens chooser of facebook, instagram, whatsapp etc.

And Explicit is

Hey, I want to share this awesome image with Instagram, open it and share the image please

Which opens instagram only (by package).

dilix
  • 3,761
  • 3
  • 31
  • 55
  • People don't seem to agree with this. See [this](https://stackoverflow.com/questions/2914881/android-implicit-intents-vs-explicit-intents/13329731). Currently, there are 170 upvotes on answers containing a stricter definition, i.e. explicit means that defined component should handle the intent. Not to mention other relevant questions... – Tamás Bolvári Feb 05 '19 at 17:12
  • @TamásBolvári Updated the answer with how I see that – dilix Feb 05 '19 at 18:21
  • If a specific component is not supplied, then it is merely implied, so "leaving nothing merely implied" is not the case. If an explicit category or explicit action doesn't make an implicit intent explicit, why does an explicit package name? The definition of explicit is clear, as opposed to the definition of explicit intent. There should be a clear definition of **explicit intent** on developers.android.com, without contradicting information. – Tamás Bolvári Feb 06 '19 at 08:41
  • What the idea of the question btw? I mean what do you need the exact definition for? – dilix Feb 06 '19 at 09:48
  • I want to be able to determine the type of intents, because the platform's behavior depends on it. In [my previous question](https://stackoverflow.com/questions/54492708/why-is-no-activity-found-to-handle-intent) I use the same intent as in this question, and someone advises to add the default category to the target app's manifest to make my "_implicit_" intent work, even though my intent is explicit by [the definition of developer.android.com](https://developer.android.com/guide/components/intents-filters#Types) ("_...supplying either the target app's package name or..._"). – Tamás Bolvári Feb 06 '19 at 10:08