4

If an app has multiple screens it means that it has multiple activities.

When a user launches the app, the first screen to appear is the Main Activity.

Does an app always start from the Main Activity?

bart
  • 1,003
  • 11
  • 24
  • Google is now advocating that developers break up their larger apps into smaller app bundles, where each bundle has its own discreet functionality. In that way, the whole app doesn't have to be loaded into memory if the user is just using a small part of the app. Check out 'Deep Linking' to see how you can define multiple entry points for your app. – Michael Dougan Jul 12 '19 at 16:51
  • 1
    @MichaelDougan That both doesn't answer his question, and doesn't make sense for the vast majority of apps out there. – Gabe Sechan Jul 12 '19 at 18:27
  • @Gabe Sechan, the possibility of multiple entry points into an app directly addresses the question of whether the Main Activity is always the first Activity to start. The answer is no, it depends on whether you have more than one entry point to your app or not. Many apps are coded as Android Instant Apps, which have a separate entry point when being run as an Instant App, and when being run as a downloaded and installed app. Different entry points, different Activities used on start. But you are entitled to your opinion. – Michael Dougan Jul 12 '19 at 18:43
  • @MichaelDougan And all of it is nothing new, any android app could have as many entry points as it wanted dating back to v3. You can even get multiple icons in the app drawer for different activities. But your answer was a total digression going into things that had nothing to do with what he asked. There was no need, or value, in bringing in app bundles to the conversation – Gabe Sechan Jul 12 '19 at 18:52

3 Answers3

13

Go to your manifest file in your android studio.

You will see something like this:

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

The name of the activity that will show there is the first activity to launch, you can read more about it here

You can change this activity to another activity if you would like to, MainActivity is a default when you create a new project.


For example:

replace <activity android:name=".MainActivity">

with <activity android:name=".SecondActivity">

And now SecondActivity will show first.

Community
  • 1
  • 1
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
1

No, the Main Activity starts when the user click on the app icon. And then the system launches an instance of the Main Activity and loads its layout.

However it's also possible to take the user to a different Activity, for example from a notification or from another app.

bart
  • 1,003
  • 11
  • 24
1

An app can have multiple screens with a single activity if you use fragments.

Also starting activity can be set in AndroidManifest.xml, Just add this to the activity that you want to start with:

<intent-filter>
    <action android:name=
        "android.intent.action.MAIN" />
    <category android:name=
        "android.intent.category.LAUNCHER" />
</intent-filter>
Mohammad Kurjieh
  • 1,043
  • 7
  • 16