Intent and Intent Filters

Intent: Intent is a messaging object, it is a data structure containing a description of to-be-performed operation. Using intents we can send messages asynchronously to other component.

Intents are 2 types.

  1. Explicit Intent: In explicit intent we will specify the component name which we want to start. In our application we mostly use explicit intent because we know which component(Activity, Service or Broadcast Receiver).

Example:

Intent intent = new Intent(MainActivity.this, AboutTgActivity.class); 
                startActivity(intent);

      2. Implicit Intent: For implicit intent we just specify the action then the android framework will take care of launching the specified action component. If more than one component is found for specified action then it will prompt all available components then user can select any of one.

Example:

        Uri articleURL = Uri.parse(articleUrlString);
        Intent i = new Intent(Intent.ACTION_VIEW, articleURL);
        startActivity(i);

 

Intent Filters:

Using intent filter we can specify which actions can be performed in a specific component. Intent filters we normally specify in the manifest.xml.  In intent filter we can specify only one action and multiple categories which can handle the given action also we can specify the data type.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s