如何将我的Activity设置为android中的主要活动? [重复]

时间:2022-01-11 20:53:28

This question already has an answer here:

这个问题在这里已有答案:

I want to create own activity as main activity rather than using default MainActivity.

我想创建自己的活动作为主要活动,而不是使用默认的MainActivity。

How can I define that in android manifest?

如何在android清单中定义它?

5 个解决方案

#1


52  

In your manifest file , use the below code to declare an activity as a launcher activity:

在清单文件中,使用以下代码将活动声明为启动器活动:

<activity android:name=".yourActivityName" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

From Android Developer docs:

来自Android Developer docs:

ACTION_MAIN activity: Start up as the initial activity of a task, with no data input and no returned output.

ACTION_MAIN活动:作为任务的初始活动启动,没有数据输入且没有返回的输出。

CATEGORY_LAUNCHER: The activity can be the initial activity of a task and is listed in the top-level application launcher`.

CATEGORY_LAUNCHER:活动可以是任务的初始活动,并列在*应用程序启动器中。

#2


11  

In AndroidManifest.xml file inside application tag add an activity tag and remove action MAIN from old activity tag set that as default

在应用程序标记内的AndroidManifest.xml文件中添加活动标记,并从默认的旧活动标记集中删除操作MAIN

 <application...... >
    <activity
        android:name=".DefaultActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".NewActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 </application>

#3


4  

You can use in manifest file:

您可以在清单文件中使用:

<activity
    android:name=".DefaultActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name=".NewActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity> 

It is very important:

这是非常重要的:

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

#4


2  

It's Simple. In your android manifest file add,

这很简单。在你的android清单文件中添加,

<activity
    android:name="Your Activity Name"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

#5


1  

In Xamarin, you can add MainLauncher = true above class definition like this:

在Xamarin中,您可以在类定义之上添加MainLauncher = true,如下所示:

[Activity(Label = "UserActivity", MainLauncher = true)]
public class UserActivity : ListActivity

#1


52  

In your manifest file , use the below code to declare an activity as a launcher activity:

在清单文件中,使用以下代码将活动声明为启动器活动:

<activity android:name=".yourActivityName" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

From Android Developer docs:

来自Android Developer docs:

ACTION_MAIN activity: Start up as the initial activity of a task, with no data input and no returned output.

ACTION_MAIN活动:作为任务的初始活动启动,没有数据输入且没有返回的输出。

CATEGORY_LAUNCHER: The activity can be the initial activity of a task and is listed in the top-level application launcher`.

CATEGORY_LAUNCHER:活动可以是任务的初始活动,并列在*应用程序启动器中。

#2


11  

In AndroidManifest.xml file inside application tag add an activity tag and remove action MAIN from old activity tag set that as default

在应用程序标记内的AndroidManifest.xml文件中添加活动标记,并从默认的旧活动标记集中删除操作MAIN

 <application...... >
    <activity
        android:name=".DefaultActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".NewActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 </application>

#3


4  

You can use in manifest file:

您可以在清单文件中使用:

<activity
    android:name=".DefaultActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name=".NewActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity> 

It is very important:

这是非常重要的:

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

#4


2  

It's Simple. In your android manifest file add,

这很简单。在你的android清单文件中添加,

<activity
    android:name="Your Activity Name"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

#5


1  

In Xamarin, you can add MainLauncher = true above class definition like this:

在Xamarin中,您可以在类定义之上添加MainLauncher = true,如下所示:

[Activity(Label = "UserActivity", MainLauncher = true)]
public class UserActivity : ListActivity