How to add Activity to manifest.xml in right way?

前端 未结 6 643
春和景丽
春和景丽 2020-12-24 03:16

should I write each activity in android manifest and how? Must each activity have intent-filter, or not?

相关标签:
6条回答
  • 2020-12-24 03:29

    only android:name="ActivtyName" is necessary.

    0 讨论(0)
  • 2020-12-24 03:38

    An activity must be mentioned inside an

    <activity>
        ...
    </activity> 
    

    tag. Each of the activity tags must be specified inside

    <application>
        ...
    </application> 
    

    tag.

    The default activity needs to have a

    <intent-filter>
        ...
    </intent-filter>
    

    tag which will make the android system understand that this activity will be called at the time of App Launch.

    A can contain several attributes however, only the name attribute is mandatory.

    Following is the complete list: https://developer.android.com/guide/topics/manifest/activity-element

    Default Activity Tag:

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

    Other Activity Tag:

        <activity
            android:name=".SelectSubjectActivity"
            android:windowSoftInputMode="adjustResize" />
    
    0 讨论(0)
  • 2020-12-24 03:41

    Multiple ways to add activites in Manifest file.

    intent filter is not a necessary tag for all activites,it is optional.

    Add Activity in application tag in your manifest:

     <!-- Main Activity-->
        <activity android:name=".YourActivityName" >
            <intent-filter>
          <!-- MAIN represents that it is the Main Activity-->
                <action android:name="android.intent.action.MAIN" />
          <!-- Launcher Denotes that it will be the first launching activity-->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
     <!--Add Other activities like this-->
        <activity android:name=".YourActivityName2" >
     <!--Default Intent Filter-->
            <intent-filter>
                <action android:name="android.intent.action.DEFAULT" />
            </intent-filter>
        </activity>
     <!--OR Other activities like this And  intent filter is not necessary in other activites-->
        <activity android:name=".YourActivityName3" >
        </activity>
     <!--OR Add Other activities like this-->
        <activity android:name=".YourActivityName4" />
    
    0 讨论(0)
  • 2020-12-24 03:42

    If you are using Eclipse ADT, when creating new Activity instead of creating a class create a Activity from New > Others... This way ADT automaticly adds your Activity to Manifest.

    0 讨论(0)
  • 2020-12-24 03:43

    You must mention each activity in android manifest.

    Not all activity need intent filter. intent filters show when to launch this activity. usually you will have one activity with intent filter that is to show that it is first activity when application is launched.

    inside application tag in your manifest:

            <activity android:name="ActivtyName" >
            </activity>
            <activity android:name="ActivtyName2" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
    0 讨论(0)
  • 2020-12-24 03:47

    You have to write entry in manifest for every activity and No intent filter is not necessary. You can simply write this :

     <activity
                android:name="com.example.chatter.List"
                android:label="@string/title_activity_list" >
            </activity>
    
    0 讨论(0)
提交回复
热议问题