How to add Activity in manifest.xml correctly?

Do I have to write every activity in the android manifest and how? Should each activity have an intent filter or not?

+6
source share
5 answers

Several ways to add actions to a manifest file.

an intent filter is not a necessary tag for all types of activity; it is optional.

Add activity to the application tag in the 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" /> 
+17
source

You must specify each action in the android manifest.

Not all activity needs filters are needed. Intent filters show when to start this activity. usually you will have one action with an intent filter to show that this is the first activity when the application starts.

inside the 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> 
+1
source

If you use Eclipse ADT, when creating a new Activity, instead of creating a class, create an Activity from New> Others ... This way ADT automatically adds your activity to the manifest.

+1
source

only android: name = "ActivtyName" is required.

0
source

You need to write a manifest entry for each action, and no intent filter is needed. You can simply write this:

  <activity android:name="com.example.chatter.List" android:label="@string/title_activity_list" > </activity> 
-1
source

All Articles