I'm confused about the difference between implicit and explicit intents. What is the purpose of implicit and explicit intents, and why are these concepts used?
I am new to Android applications, so please provide some examples.
Each intent filter specifies the type of intents it accepts based on the intent's action, data, and category. The system delivers an implicit intent to your app component only if the intent can pass through one of your intent filters.
Activity is a UI component which you see on your screen. An Intent is a message object which is used to request an action from the same/different app component.
Implicit Intent doesn't specifiy the component. In such case, intent provides information of available components provided by the system that is to be invoked.
In android, Implicit Intents won't specify any name of the component to start instead, it declare an action to perform and it allows a component from other apps to handle it. For example, by using implicit intents we can request another app to show the location details of the user or etc.
With an intent filter you create action for your activity so other apps can call your activity via an action:
<activity android:name=".BrowserActivitiy" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
startActivity(intent);
You make a call that indicates exactly which activity class to use:
Intent intent = new Intent(this, ActivityABC.class);
startActivity(intent);
Here's an additional reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With