Thursday, 18 February 2021

 What is Intent ?

The following tasks can be done by using intent component. Intent is basically is the intention of the user, whatever he want to do in the app but in android Intent is the one of the major component available in the android system. Intent is an object which broadcast the message to android system to handle the specific action via object passed in intent.

  • Launch an activity

  • Share data between the Activities

  • Start the service

  • Open Camera to capture photo

  • Open Gallery to select photo or document

  • Display a web page

  • Dial a phone CALL

  • Broadcast a message

  • Compose an email

  • Compose an SMS



How many types of Intents?


Implicit Intent


When we/developer does not knows the another component to start with the intent, is called implicit intent. For example when you click on link then your android environment check how many browsing apps available to open this page like Opera, Uc Browser, Chrome etc.



Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/"));

startActivity(i);




Explicit Intent


When we/developer knows the another component to start with the intent, is called explicit intent. In such case, intent provides the external class to be invoked.



Intent i =new Intent(ActivityA.this,ActivityB.class);  

startActivity(i); 


How many use cases of Intents?


Start a specific activity

Start a specific Service

Deliver the intent to a specific Broadcast Receiver.



What is Intent-filter?


<activity android:name="MainActivity">

    <!-- This activity is the main entry, should appear in app launcher -->

    <intent-filter>

        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>

</activity>


<activity android:name="ShareActivity">

    <!-- This activity handles "SEND" actions with text data -->

    <intent-filter>

        <action android:name="android.intent.action.SEND"/>

        <category android:name="android.intent.category.DEFAULT"/>

        <data android:mimeType="text/plain"/>

    </intent-filter>

    <!-- This activity also handles "SEND" and "SEND_MULTIPLE" with media data -->

    <intent-filter>

        <action android:name="android.intent.action.SEND"/>

        <action android:name="android.intent.action.SEND_MULTIPLE"/>

        <category android:name="android.intent.category.DEFAULT"/>

        <data android:mimeType="application/vnd.google.panorama360+jpg"/>

        <data android:mimeType="image/*"/>

        <data android:mimeType="video/*"/>

    </intent-filter>

    <!-- This activity also handles web page link support -->

<intent-filter>

    <category android:name="android.intent.category.DEFAULT" />

    <category android:name="android.intent.category.BROWSABLE" />

    ...

</intent-filter>

</activity>



No comments:

Post a Comment