Friday 6 January 2012

Changing Main Activity of Android Project

When we create a new Android project in Eclipse, it will set the activity (Created at the time of making a new android project project) to be the main Activity.

If you create another Activity and you want that Activity to be called as the main Activity.

Then you have to edit the 'AndroidManifest.xml' file from your Android Project.

How it works :
When an Android application is allowed to run, the host loads the application and reads the 'AndroidManifest.xml' file. It looks for an activity or activities with an intent-filter that has the MAIN action with a category of LAUNCHER and starts that activity.

How to do it :
So if you want to change the main activity of your android project, you need to CUT the following code from your previous main activity and PASTE it into the new activity which you want to set as a main activity for your android project.

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

Note : 
An Android Project may have more then one activities with
<category android:name="android.intent.category.LAUNCHER"> attribute.
But there should be only one activity having
<action android:name="android.intent.action.MAIN"> attribute in the AndroidMainfest.xml file.

No comments:

Post a Comment

About Us | Site Map | Privacy Policy | Contact Us | Blog Design | 2007 Company Name