Difference between implicit and explicit intents [

2019-03-23 11:51发布

This question already has an answer here:

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.

2条回答
我命由我不由天
2楼-- · 2019-03-23 12:22

Implicit activity call

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);

Explicit activity call

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

查看更多
何必那么认真
3楼-- · 2019-03-23 12:37
  1. Explicit Intent: Explicit intent names the component.

  2. Implicit Intent: Implicit Intents have not specified a component.

E.g: The java class which should be called Implicit intent asked the system to perform a service without telling the system which java class should do this service.

查看更多
登录 后发表回答