Change Main Activity in Android

Often we miss out adding splash screen of the application in the initial development phases, or for an instance you might want to change the main activity or the launcher activity at some later stage of development. In order to incorporate this change, a minor modification in AndroidManifest.xml file is to be done.

Say you have two activities A and B. Say initially A is the main activity and now you want to make activity B as the main activity. Open the AndroidManifest.xml file. Initially the entry for activity A in the manifest looks like:

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

Either delete the lines in the intent-filter tag or replace the activity name with B and add a new entry for activity A.

Overall the activity B’s entry should be like:

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

A single line entry for activity A will look like:

<activity android:name=".A"></activity>

It’s pretty simple and clear, all you have to do is replace the name or add a new entry.

Leave a Reply

Follow

Get notified with the latest posts

Plugin Supporter WordPress Post Navigation
%d bloggers like this: