简体   繁体   English

Android如何根据给定的Intent找到特定的活动或服务?

[英]How can android find a certain activity or service based on a given Intent?

Suppose that I installed app A and app B, app A has a main activity, and app B wants to show that activity by sending a intent. 假设我安装了应用程序A和应用程序B,应用程序A有一个主要活动,而应用程序B要通过发送意图来显示该活动。 My question is that how android knows I have installed app A and is able to map the intent to its activity? 我的问题是,Android如何知道我已经安装了应用程序A并能够将意图映射到其活动? Is there any windows-registry-like store saving such information? 是否有类似Windows注册表的商店保存此类信息?

Thank You 谢谢

I'm also new to android. 我也是android的新手。 This is how I understand Intents: 这就是我对Intent的理解:

Look in your AndroidManifest.xml. 查看您的AndroidManifest.xml。 There you define activities and intent filters: 您可以在其中定义活动和意图过滤器:

<activity android:name=".Settings.SettingsView"
        android:label="@string/settings">
    <intent-filter>
        <action android:name="at.MyApp.Settings.action.EDIT_TITLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

When you install your App those activities/services/etc get know to Android. 当您安装应用程序时,这些活动/服务/等会被Android所了解。 You tell Android, that you are able to provide an activity for "at.MyApp.Settings.action.EDIT_TITLE" If you start an activity, you create an Intend: 您告诉Android,您可以为“ at.MyApp.Settings.action.EDIT_TITLE”提供活动。如果您启动活动,则可以创建一个Intend:

startActivity(new Intent("at.MyApp.Settings.action.EDIT_TITLE"));

Anyone can try to start such an activity/service/etc throw an intent. 任何人都可以尝试启动这样的活动/服务/等等。

If two applications are able to provide some functionality for an intent, Android will ask the user which activity it should use. 如果两个应用程序能够为某个意图提供某些功能,则Android会询问用户应使用哪种活动。

That's how I understand Intents. 这就是我理解意图的方式。 If someone knows better I'll be happy to learn. 如果有人知道的更好,我会很高兴学习。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM