-1

This might be a very stupid question, but I am not quite clear on the answer.

  1. My implicit intent contains an action, data & category (optional), which I pass while sending the intent either through startActivity or startService.

something like this we normally do,

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Standing on the Moon!");
startActivity(intent);

and then we have the same operation done in a different way, using an intent filter in manifest file like

<activity android:name="ShareActivity">
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="text/plain"/>
    </intent-filter>
</activity>

My question - is both the way to declare this is for the same purpose, the two different ways they are declared, does they hve different significance???

akash89
  • 881
  • 3
  • 12
  • 31
  • the first is a call, the second is declaration. It's like saying that you don't need method signature because you call your method, so they have to exist. – njzk2 Jul 20 '15 at 19:00
  • Don't use implicit Intents when starting components of your own app - use explicit Intents which reference your ShareActivity.class explicitly. The reason for not using implicit Intents is you can't guarantee your app component will be used and you may see unexpected behaviour. – Squonk Jul 20 '15 at 19:07

1 Answers1

4

As I recall, referencing your application as an intent filter from the manifest file will let other applications know that you are capable of handling that intent. Therefore, if you are capable of sending mail and you register yourself this way in your manifest, another application can use yours to send e-mails.

This is often seen with gallery applications. Applications seldom create their own unless they themselves are a gallery application. Therefore, they will ask the Android system what gallery/mail applications are available, and let you choose one from a list. When you register yourself as an application capable of handling this intent you will find your application in this list.

I do believe that is one main difference between the two, as the programmatic instantiation is not known by other applications.

Jay Snayder
  • 4,298
  • 4
  • 27
  • 53