user1443721
user1443721

Reputation: 1260

<activity> without <intent-filter> in AndroidManifest.xml

I know I need to use to enable an activity to receive an Intent like this (not main activity).

<activity android:name=".MyApp_2ndActivity">
    <intent-filter>
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

However, I found it can be triggered too if "intent-filter" is removed, like this.

<activity android:name=".MyApp_2ndActivity">
</activity>

I am wondering what difference is in these 2 formats?

Upvotes: 3

Views: 2212

Answers (3)

user3506595
user3506595

Reputation: 139

Difference is the when we use this code:

<activity android:name=".MyApp_2ndActivity">
<intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

This will be the first activity triggered when you starts your application.It doesnot need any explicit intents

and when we use this code:

<activity android:name=".MyApp_2ndActivity">
</activity>

the activity will be started with the use of Explicit intent

Upvotes: 1

Karakuri
Karakuri

Reputation: 38595

See here: http://developer.android.com/guide/components/intents-filters.html

The difference is the second one can only be started using an explicit Intent -- one which names the component it wants to start. The first one can be started by an implicit Intent -- one which does not specify the exact component but contains information for the system to find an appropriate match for. The intent filters are used by the system for resolving such intents.

Upvotes: 3

MikkoP
MikkoP

Reputation: 5092

Intent filters are used, for example, when the activity starts from a specific event on the device. Your main activity has specific intent filters. If you want your application start when NFC tag is scanned, you can specify that via intent filters.

You can read more here for example.

http://developer.android.com/guide/components/intents-filters.html

Upvotes: 0

Related Questions