1

I have a android studio project, and I have got few layouts which are connected to their .java files

note "I couldn't post images as of my low reputation"

I have got:

  1. layout1.xml
  2. layout2.xml
  3. layout3.xml
  4. layout4.xml
  5. layout5.xml

and

  1. Layout1.java
  2. Layout2.java
  3. Layout3.java
  4. Layout4.java
  5. Layout5.java

Android Manifest is:

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@drawable/blablabla"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:screenOrientation="portrait"
        android:name="com.icetea09.demomaterialdesigndrawermenu.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

layout1.xml code is this: "activity_main.xml is my layout1"

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mLvDrawerMenu = (ListView) findViewById(R.id.lv_drawer_menu);

    List<DrawerMenuItem> menuItems = generateDrawerMenuItems();
    mDrawerMenuAdapter = new DrawerMenuItemAdapter(getApplicationContext(), menuItems);
    mLvDrawerMenu.setAdapter(mDrawerMenuAdapter);

    mLvDrawerMenu.setOnItemClickListener(this);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.app_name, R.string.app_name) {
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if(savedInstanceState == null){
        setFragment(0, BikeFragment.class);
    }
}

The default layout load view is "layout1.xml with Layout1.java"

The question is how do I change the start view layout from layout1 to layout2. Like when I install the app first, It will show the "layout2.xml" view instead of default one which is layout1.xml in my case.

Thank you for your time.

sharben
  • 129
  • 4
  • 14

1 Answers1

8

One way to do it, is when you add a new activity. You can click on "Launcher Activity". Then Android Studio will make this new activity the Launcher Activity.

When you already have added both activities there is another way.

The best way is to use the

AndroidManifest.xml    

file. To make an activity seen as a launcher activity you add the following attributes to your activity in the manifest:

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

This question may be a duplicate: change application's starting activity - Android

Community
  • 1
  • 1
E. Verdi
  • 310
  • 2
  • 19