How can you know what the main launch Activity is?

2019-06-21 05:15发布

Newb question. How can you know what the main launch Activity is? Learning Android.

5条回答
我命由我不由天
2楼-- · 2019-06-21 05:35

The main activity can be considered the one which handles the initial screen of the application you're creating.

 ?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="clustering.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" 
              android:targetSdkVersion="11" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:icon="@drawable/gene_launcher"
        android:label="@string/app_name" >
       <activity
           android:name=".MainActivity"
           android:label="@string/app_name" >
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
       <activity android:name=".yourSubActivity"  android:label="@string/<ActivityName>"> </activity>
     ...list of other activities...
   </application>

</manifest>
查看更多
女痞
3楼-- · 2019-06-21 05:37

You have to put the right intent tag on the activity in the manifest:

    <activity android:name=".SomeActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
查看更多
ら.Afraid
4楼-- · 2019-06-21 05:40

The main activity can be found and set in AndroidManifest.xml; look for

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

The <activity> with that action is the main activity (is the entry point for the app).

查看更多
甜甜的少女心
5楼-- · 2019-06-21 05:55

You can look into AndroidManifest.xml in your porject

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

This will help you to find Launch activity.

查看更多
一纸荒年 Trace。
6楼-- · 2019-06-21 05:59

Assuming this is for your code, check out the manifest.xml and look for this element:

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

It should be contained within <Activity> ... </Activity> tags, and that Activity is the one that a user can launch from their phone.

查看更多
登录 后发表回答