How to change launcher activity in android studio, set default activity for Android application, android launcher

How to change launcher activity in android studio

By default when you launch an application on your phone there is a screen that loads as the first screen despite having other major screens present in the application.

For example, in applications that require log in, the login screen is mostly loaded first so that the application can identify you before you access the app components, or in some others, a screen with the logo of the app called splash screen is loaded first. This screen that is loaded first is the one called launcher activity in android studio.

By default, when you create an app in the android studio it creates an activity called MainActivity that acts as the launcher activity by default.

The MainActivity screen that has been created can have main components of the app but in the process of developing your application, you decide to add the welcome screen without altering the components of the MainActivity screen meaning you will be forced to change the first screen from the default MainActivity to your welcome screen.

In this article, we shall highlight the few steps that are required to ensure you change the launcher activity in android studio to your desired screen. The process is straight forward and it should be a must-know for every android developer.

To begin,

  • You need to have created a project in android studio (you can follow how to do this in a previous article on how to create your first android application
  • If you have only the MainActivity activity only in your android project, you will need to add the other activity which will be your launcher activity

To create a new activity in android studio,

  • In the top left, right-click on the app
  • Then click on New
  • Then click on the activity
  • Then choose an empty activity
  • Add the activity name as the name of your choice, in this example, I will use WelcomeActivity and click on finish
  • Now the welcome activity will be set up, you can add your design and functionality as you choose.

 

  • In the manifests folder, click on AndroidManifest.xml, this file contains the configurations of all activities present in your app

You will notice that the default main activity has an additional intent called intent as shown below

How to change launcher activity in android studio, set default activity for Android application, android launcher

Change launcher activity in android studio

  • To change the launcher activity from MainActivity to WelcomeActivity cut the intent filter code from main activity and paste it in the welcome activity
  • The welcome activity code will be as shown below

<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter&ht;
</activity>

 

  • The full code of the android manifest file will be as below

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.solutionspaceapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SolutionSpaceApp">
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
</application>
</manifest>

  • Click save and run your app

 

The steps we have highlighted above are the ones used to change the launcher activity in android studio and so far we hope you have taken keenly everything that is required.