Monday, August 25, 2014

Intent Filters

Intent Filters are used to register
  • Activities
  • Services
  • Broadcast Receivers 
as being capable of performing an action on a particular kind of data

Using Intent Filters, application components announce that they can respond to action requests from
any application installed on the device.

To register an application component as a potential Intent handler, add an intent-filter tag to the
component’s manifest node using the following tags (and associated attributes) within the Intent Filter node:

action 
  • android.intent.action.MAIN indicates that the activity serves as the entry point for the application
category
  • ALTERNATIVE
  • SELECTED_ALTERNATIVE
  • BROWSABLE
  • DEFAULT
  • GADGET
  • HOME
  • LAUNCHER
    • Indicates that the application can be launched from the device's launcher icon.

data
  • android:host
  • android:mimetype
  • android:path
  • android:port
  • android:scheme

Registering an Activity as an Intent Receiver

action: specifies the name of the action being serviced
category: under which circumstance the action should be serviced
data: data types the component can act on 

<activity android:name= android:label= >
      <intent-filter>
         <action android:name= > </action>
         <category android:name="android.intent.category.DEFAULT"/>
         <category android:name="android.intent.category.ALTERNATIVE_SELECTED">
         <data android:mimeType=         />
      </intent-filter>
</activity>


How Android resolves Intent Filters


Finding and Using the Launch Intent in a Sub-Activity

When an application component is started to serve an implicit intent, it needs to find the action it's to perform and the data to perform it on.

@Override
public void onCreate(Bundle bundle)
{
      super.onCreate(bundle);
      setContentView(R.layout.main);

      Intent intent = getIntent();

      String action = intent.getAction();
      Uri data = intent.getData();

      //passing on responsibility
      if(someCondition)
         startNextMatchingActivity(intent);
}

No comments:

Post a Comment