0

In my new android sudio project I created two activities. The first is the MainActivity and the second is called SecondActivity. The second is more like a sort of menù. Logically, when the app starts, SecondActivity must appear as first.

In the manifest I declared both the activities but I don't know how to declare them correctly so that SecondActivity appears as the first activity in the application after I loaded it on my Android device.

This is my project's manifest :

<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/AppTheme">
        <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=".SecondActivity"> </activity>
    </application>
1
  • <activity android:name=".MainActivity"> to <activity android:name=".SecondActivity"> and second activity change to Main
    – Ivan86
    May 29, 2017 at 15:31

4 Answers 4

1

Did you tried this, my friend

<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/AppTheme">
        <activity android:name=".MainActivity"></activity>
        <activity android:name=".SecondActivity"> 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
0

Two options...

1) Move the intent filter.

2) Switch the android:name property since ordering does not matter

0

Try this:

<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/AppTheme">
    <activity android:name=".MainActivity">

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

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

The intent-filter tag let you choose trough the action wich activity will be the main.

0

Simply move the intent filters to the second activity like so:

...

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

...

The parts between the intent-filter tags (<intent-filter> and </intent-filter>) tell Android that this activity should be used when the launcher icon of your app is pressed (i.e. the initial activity).

Not the answer you're looking for? Browse other questions tagged or ask your own question.