Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 801
Wesik Avatar asked Jan 01 '14 15:01

Wesik


2 Answers

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" /> 
like image 194
Hamad Avatar answered Oct 12 '22 21:10

Hamad


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" /> 
like image 43
Dibyendu Mitra Roy Avatar answered Oct 12 '22 23:10

Dibyendu Mitra Roy