How to set my Activity as main activity in android? [duplicate]

≯℡__Kan透↙ 提交于 2019-12-17 22:32:38

问题


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

How can I define that in android manifest?


回答1:


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:

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

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




回答2:


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

 <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:


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:


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

<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:


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

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


来源:https://stackoverflow.com/questions/9704898/how-to-set-my-activity-as-main-activity-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!