How to change the startup activity in android?-ThrowExceptions

Exception or error:

I have two activities namely login and calendar in my Application. Currently my startup activity is “calendar“. I want to run the login as first activity not calendar.

How to solve:

The startup activity [Launcher Activity] is declared in the projects’ AndroidManifest.xml file

Look for that activity tag in the manifest which looks like this

<activity android:name=".Main"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.

That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.

###

Add Intent filter to the Activity in which you want startup.
In your case Modify the AndroidManifest.xml file as follows

<activity android:name=".login"
      android:label="@string/app_name">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

###

remove the intent-filter code from calendar Activity tag in manifest and add it to the Activity you wanna load first

 <intent-filter>
       <action android:name="android.intent.action.MAIN" />

       <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>

I mean paste it in the activity you like to run as default.

 <activity
            android:name="com.example.gridviewimages.AnotherActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Where as

From the docs

category -- Gives additional information about the action to execute. For example, 

CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while 

CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can 

perform on a piece of data.

MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.

###

You want the Application element of the Android Manifest file. You can see details here.
Look at the name attribute, this points to the Application class.

Leave a Reply

Your email address will not be published. Required fields are marked *