在Android中,您可以通过遵循“ AndroidManifest.xml ”中的“ intent-filter ”来配置应用程序的启动活动(默认活动)。
请参阅以下代码片段,将活动类“ logoActivity ”配置为默认活动。
档案:AndroidManifest.xml
<activity
android:label="Logo"
android:name=".logoActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
例如,假设您有两个活动类,并且要将“ ListMobileActivity
”活动设置为应用程序的起始活动。
档案:AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="List of Mobile OS"
android:name=".ListMobileActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="List of Fruits"
android:name=".ListFruitActivity" >
</activity>
</application>
</manifest>
另一方面,如果要将“ ListFruitActivity
”活动设置为开始活动,只需剪切并粘贴“ intent-filter ”,如下所示:
档案:AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="List of Mobile OS"
android:name=".ListMobileActivity" >
</activity>
<activity
android:label="List of Fruits"
android:name=".ListFruitActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
翻译自: https://mkyong.com/android/how-to-set-default-activity-for-android-application/