Android tutorial - Android Default Activity | How to set default activity for Android application - android app development - android studio - android development tutorial



What is android application?

  • An Android app is a software application running on the Android platform.
  • Because the Android platform is built for mobile devices, a typical Android app is designed for a smartphone or a tablet PC running on the Android OS.
  • android acitivity life cycle
  • In Android, you can configure the starting activity (default activity) of your application via following “intent-filter” in “AndroidManifest.xml“.
  • The following code snippet to configure an activity class “logoActivity” as the default activity.
 android default activity

File: AndroidManifest.xml

<activity
    android:label="Logo"
    android:name=".logoActivity" >
     <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
click below button to copy the code from android tutorial team
  • For example, let said you have two activities class, and you want to set the “ListMobileActivity” activity as the starting activity of your application.

File: AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wikitechy.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="List of Mobile OS"
            android:name=".ListMobileActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="List of Fruits"
            android:name=".ListFruitActivity" >
        </activity>
    </application>

</manifest>
click below button to copy the code from android tutorial team
  • On the other hand, If you want to set the “ListFruitActivity” activity as your starting activity, just cut and paste the “intent-filter” like following:

File: AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wikitechy.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="List of Mobile OS"
            android:name=".ListMobileActivity" >
        </activity>
        <activity
            android:label="List of Fruits"
            android:name=".ListFruitActivity" >
             <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
click below button to copy the code from android tutorial team

Related Searches to Android Default Activity | How to set default activity for Android application