3.2.3 在AndroidManifest 文件中注册 <intent-filter>标签 配置主Activity的方法

配置主Activity的方法:

在<activity>标签的内部加入<intent-filter>标签,并在标签里添加

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

这两句声明即可

那什么是<intent-filter>标签:

在Android开发中,<intent-filter>标签用于定义应用组件(如Activity、Service或Broadcast Receiver)如何响应Intent。主要包含以下几个关键属性:

  1. Action:表示一个动作的字符串,系统通过这个属性来识别和执行相应的操作。例如,"android.intent.action.MAIN"代表应用的入口Activity。
  2. Category:用于进一步细化Action,它为Intent提供了额外的信息以帮助系统确定如何处理该Intent。比如,"android.intent.category.LAUNCHER"通常与"android.intent.action.MAIN"结合使用,表示该Activity是主入口并且会在启动器中显示出来。
  3. Data:指定了URI和数据的格式,用于过滤那些可以处理特定类型数据的Intent。比如,可以通过设置Data属性让某个Activity响应特定类型的URL或者特定路径的文件。
  4. Extras:提供额外的键值对数据,这些数据可以在发送Intent时附加给接收方使用。

此外,当Android系统收到一个Intent时,会根据Intent中的Action、Category等信息,以及在Manifest文件中声明的<intent-filter>标签内容进行匹配,从而决定启动哪个应用组件。这个过程类似于一个过滤器,筛选出最合适的组件来处理特定的Intent。

示例代码修改:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AvtivityTest"
        tools:targetApi="31">
        <activity android:name=".FirstActivity"
            android:label="This is the FirstActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

  • 9
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 Spring MVC 的 pom.xml 配置文件示例: ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>spring-mvc-demo</artifactId> <version>1.0-SNAPSHOT</version> <properties> <spring.version>5.2.9.RELEASE</spring.version> <javax.servlet.version>3.1.0</javax.servlet.version> </properties> <dependencies> <!-- Spring MVC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!-- Servlet API --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${javax.servlet.version}</version> </dependency> </dependencies> <build> <plugins> <!-- Maven Compiler Plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!-- Maven WAR Plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.3</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> </project> ``` 注意,这里的版本号仅供参考,您可以根据需要调整版本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值