Skip to content Skip to sidebar Skip to footer

How To Add Activity To Manifest.xml In Right Way?

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

Solution 1:

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--><activityandroid:name=".YourActivityName" ><intent-filter><!-- MAIN represents that it is the Main Activity--><actionandroid:name="android.intent.action.MAIN" /><!-- Launcher Denotes that it will be the first launching activity--><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><!--Add Other activities like this--><activityandroid:name=".YourActivityName2" ><!--Default Intent Filter--><intent-filter><actionandroid:name="android.intent.action.DEFAULT" /></intent-filter></activity><!--OR Other activities like this And  intent filter is not necessary in other activites--><activityandroid:name=".YourActivityName3" ></activity><!--OR Add Other activities like this--><activityandroid:name=".YourActivityName4" />

Solution 2:

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:

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

Other Activity Tag:

<activityandroid:name=".SelectSubjectActivity"android:windowSoftInputMode="adjustResize" />

Solution 3:

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:

<activityandroid:name="ActivtyName" ></activity><activityandroid:name="ActivtyName2" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>

Solution 4:

only android:name="ActivtyName" is necessary.

Solution 5:

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.

Post a Comment for "How To Add Activity To Manifest.xml In Right Way?"