Android的Manifest-意图过滤器和活动过滤器、意图、Android、Manifest

2023-09-07 08:34:21 作者:rebirth 重生

可能有人在清单中解释如下 -

 <活动
        机器人:关于我们NAME =
        机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=com.example.app1.ABOUT/>
            <类机器人:名称=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>

    < /活性GT;
 

如何在活动和意图过滤器等领域重要的,当他们使用/提及? 对不起,我试图阅读文件,但仍不可能推测出很多。

感谢您

解决方案

 机器人:关于我们NAME =
 
在安卓应用androidmanifest.xml中的application标签中加入android

这是你的Activity类的名称,点在前面是你的包速记符号。因此,这实际上代表 com.your.package.name.AboutUs 这意味着重新presents这个活动叫做关于我们你的java文件。 java的

 机器人:标签=@字符串/ APP_NAME
 

标签是获取示于启动器(如果该活动被列在发射器)的字符串,并在窗口的顶部,当活动是开放

 <意向滤光器> ...&所述; /意图滤光器>
 

意图过滤器,以推出定义了你的活动监听的意图。

 <作用机器人:名称=com.example.app1.ABOUT/>
<类机器人:名称=android.intent.category.DEFAULT/>
 

动作和类别是得到的一个Intent设置之前,炒客进入系统两个领域。然后,系统将寻找符合双方的动作和类别的活动,如果找到一个,那么它将启动该活动,或者如果它找到多个它会显示用户所有的人,让他们挑选。

在你的情况下,您正在收听的 com.example.app1.ABOUT 的动作是一个自定义操作特定于您的应用程序,而不是系统的操作之一

所以这是一个意向,将启动这个特殊的活动可能是这样的:

 意向书我=新意图();
i.setAction(com.example.app1.ABOUT);
i.addCategory(android.intent.category.DEFAULT);
startActivity(ⅰ);
 

需要注意的是,因为你已经创建了一个自定义操作,这种意图并不需要访问你的 AboutUs.class 所以这个意图在技术上可以从任何应用程序发射的设备,它会发射到你的活动。

Could someone explain the following lines in the manifest -

    <activity
        android:name=".AboutUs"
        android:label="@string/app_name">
        <intent-filter >
            <action android:name="com.example.app1.ABOUT" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>

    </activity>    

How are the fields in activity and intent filter important and when are they used/referred ? Sorry, i tried to read the documentation but still couldnt figure much out.

Thank you

解决方案

android:name=".AboutUs"

This is the name of your Activity class, the dot at the front is shorthand notation for your package. So this actually stands for com.your.package.name.AboutUs which means your java file that represents this Activity is called AboutUs.java

android:label="@string/app_name"

label is the string that gets shown in the launcher(if the activity is listed in the launcher) and at the top of the window when the activity is open.

<intent-filter > ... </intent-filter>

intent filter defines the Intents that your activity "listens for" in order to launch.

<action android:name="com.example.app1.ABOUT" />
<category android:name="android.intent.category.DEFAULT"/>

Action and category are both fields that get set on an Intent before it is "fired off" into the system. The system will then look for any activities that match both the action and category and if it finds one then it will launch that activity, or if it finds multiple it will show the user all of them and let them pick.

In your case your the action you are listening for com.example.app1.ABOUT is a custom action that is specific to your app, not one of the systems actions.

So here is what an intent that would start this particular activity might look like:

Intent i = new Intent();
i.setAction("com.example.app1.ABOUT");
i.addCategory("android.intent.category.DEFAULT");
startActivity(i);

Note that because you've created a custom action, this intent does not require access to your AboutUs.class so this intent could technically be fired from any app on the device and it would launch into your activity.