Change application's starting activity

AndroidAndroid Activity

Android Problem Overview


I have created the meat and guts of my application but I want to add a different activity that will be the starting point (sort of a log-in screen).

Couple questions:

  • 1 I have a fairly decent handle on how to switch between activities (based on this article: http://www.linux-mag.com/id/7498) but I'm not sure how to go about creating a new one (with eclipse).

  • 2 Once I have a new activity created, how can I set it as the default activity of my application? I presume I could just change the name of the classes...but is there a more elegant way to handle that (maybe within the AndroidManifest.xml)?

Android Solutions


Solution 1 - Android

Yes, you use the AndroidManifest.xml file. You can actually even have more than one launcher activity specified in your application manifest. To make an activity seen on the launcher you add these attributes to your activity in the manifest:

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

Solution 2 - Android

Go to AndroidManifest.xml in the root folder of your project and change the Activity name which you want to execute first.

Example:

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

Solution 3 - Android

If you are using Android Studio and you might have previously selected another Activity to launch.

Click on Run > Edit configuration and then make sure that Launch default Activity is selected.

Launch default Activity

Solution 4 - Android

 <application
    android:icon="@drawable/YOUR_ICON"    <!-- THIS ICON(IMAGE) WILL BE SHOWN IN YOUR APPS -->
    android:label="MY APP NAME " >    <!-- HERE LABEL(APP NAME) -->
    <activity
        android:name=".application's starting activity"  <!-- (.)dot means current dir, if your activity is in another package then give full package name ex: com.xxx.Activity  -->
        android:label="LABEL FOR ACTIVITY "
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Solution 5 - Android

Follow to below instructions:

1:) Open your AndroidManifest.xml file.

2:) Go to the activity code which you want to make your main activity like below.

such as i want to make SplashScreen as main activity

<activity
    android:name=".SplashScreen"
    android:screenOrientation="sensorPortrait"
    android:label="City Retails">
</activity>

3:) Now copy the below code in between activity tags same as:

<activity
    android:name=".SplashScreen"
    android:screenOrientation="sensorPortrait"
    android:label="City Retails">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

and also check that newly added lines are not attached with other activity tags.

Solution 6 - Android

This is easy to fix.

  • Changes to the Launcher activity are also stored in the Debug configuration.
  • Go to Run > Debug Configurations and edit the setting.
  • There is also a similar setting in Intellij under Run > Edit Configurations select Run default Activity and it will no longer save the setting in this fashion.

Solution 7 - Android

It's simple. Do this, in your Manifest file.

<activity
	android:name="Your app name"
	android:label="@string/app_name">
		<intent-filter>
			<action android:name="android.intent.action.MAIN" />
			<category android:name="android.intent.category.HOME" />
			<category android:name="android.intent.category.DEFAULT" />
		</intent-filter>
</activity>

Solution 8 - Android

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

Solution 9 - Android

Just go to your AndroidManifest.xml file and add like below

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

then save and run your android project.

Solution 10 - Android

You add this you want to launch activity android:exported="true" in manifest file like

 <activity
      android:name=".activities.activity.MainActivity"
      android:windowSoftInputMode="adjustPan"
      android:exported="true"/>
  <activity

Open java file of this activity and right click then click on Run 'main Activity'

OR

Open java file of this activity and press Ctrl+Shift+F10.

Solution 11 - Android

In a recent project I changed the default activity in AndroidManifest.xml with:

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

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

In Android Studio 3.6; this seems to broken. I've used this technique in example applications, but when I use it in this real-world application it falls flat. The IDE once again reports:

> Error running app: Default activity not found.

The IDE still showed a configuration error in the "run app" space in the toolbar (yellow arrow in this screenshot)

Error in

To correct this error I've tried several rebuilds of the project, and finally File >> "Invalidate Cache/Restart". This did not help. To run the application I had to "Edit Configurations" and point at the specific activity instead of the default activity:

Edit configuration dialog box

Solution 12 - Android

In AndroidManifest.xml

I changed here the first activity to be MainActivity4 instead of MainActivity:

Before:

    <activity android:name=".MainActivity" >
       <intent-filter>
           <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity2" />
    <activity android:name=".MainActivity3" />
    <activity android:name=".MainActivity4" />
    <activity android:name=".MainActivity5" />
    <activity android:name=".MainActivity6"/>

After:

    <activity android:name=".MainActivity" />
    <activity android:name=".MainActivity2" />
    <activity android:name=".MainActivity3" />
    <activity android:name=".MainActivity4" >
       <intent-filter>
           <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity5" />
    <activity android:name=".MainActivity6"/>

Solution 13 - Android

For anyone getting errors in their debug\AndroidManifest.xml file make sure that you include the tag! "

For example:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKyleView Question on Stackoverflow
Solution 1 - AndroidNathan SchwermannView Answer on Stackoverflow
Solution 2 - Androidneeraj tView Answer on Stackoverflow
Solution 3 - AndroidZeezerView Answer on Stackoverflow
Solution 4 - AndroidLMKView Answer on Stackoverflow
Solution 5 - AndroidBhunnu BabaView Answer on Stackoverflow
Solution 6 - Androiduser3154790View Answer on Stackoverflow
Solution 7 - Androiduser1950448View Answer on Stackoverflow
Solution 8 - AndroidNull Pointer ExceptionView Answer on Stackoverflow
Solution 9 - Androiduser3206168View Answer on Stackoverflow
Solution 10 - AndroidPrabh deepView Answer on Stackoverflow
Solution 11 - AndroidmartshalView Answer on Stackoverflow
Solution 12 - AndroidShadyView Answer on Stackoverflow
Solution 13 - AndroidSammi LinView Answer on Stackoverflow