How to Set Default Activity for Android App

Starting or default activity of an app can be configured using the intent-filter tag in AndroidManifest.xml. A simple case you need to do this is when the app contains a splash screen which is required to be displayed first when the app is executed.

When an app is created with Android Studio, it is required to input a default activity and it is set as starting an activity in AndroidManifest.xml.

[xml]
<activity
android:name=”.MainActivity”
android:label=”@string/app_name”
android:theme=”@style/AppTheme.NoActionBar”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
[/xml]

If the app contains another activity called StartupActivity.java and you want it to be the one getting displayed when the app is opened, you need to modify the manifest file as follows.
[xml]
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.androidnames.fragmentnav”>

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity
android:name=”.MainActivity”
android:label=”@string/app_name”
android:theme=”@style/AppTheme.NoActionBar”>
</activity>
<activity
android:name=”.StartupActivity”
android:label=”@string/app_name”
android:theme=”@style/AppTheme.NoActionBar”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

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

</manifest>
[/xml]

Leave a Comment

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


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close