There is a DrawerLayout, there are several elements in the list, and for each click a new activity is opened. So at startup, the main activity should be launched, but the one that is listed first in the list should be launched.

Here is the code:

private void selectItem(int position) { switch(position) { case 0: Intent intent = new Intent(MainActivity.this, Two.class); startActivity(intent); break; сase 1: Intent intent ... 

In general, when you start the program, the Two class opens, everything is fine in the program settings, everything is written in the manifest, but I can't make it

  Intent intent = new Intent(MainActivity.this, MainActivity.class); 

Here is part of the manifesto. I thought at first, this is a trifle, but in the end something stuck on it.

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

    1 answer 1

    If you mean that when you start the application you get it like this:

    1. Run MainActivity;
    2. 0 item is selected in DrawerLayout;
    3. By choosing the 0 element, the Two class is called (also an Activity, I suppose?);

    and if you want the application to understand that this is the first launch, you can mark the first launch with a flag. For example:

    1) Create a variable in the class MainActivity

     private boolean firstLaunch=true; 

    2) In selectItem (int position), we check for the first launch of Activiti. If this is it, then we change the value of the flag, and the activation is not launched.

     private void selectItem(int position) { switch(position) { case 0: if(firstLaunch) { firstLaunch=false; } else { Intent intent = new Intent(MainActivity.this, Two.class); startActivity(intent); } break; сase 1: Intent intent ... 

    Well, do not forget to save the value of the firstLaunch variable in the onSaveInstanceState (Bundle savedInstanceState)

     onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putBoolean("flag", firstLaunch); } 

    and restore it to onCreate (Bundle savedInstanceState)

     onCreate(Bundle savedInstanceState) { ... if(savedInstanceState!=null) { this.firstLaunch=savedInstanceState.getBoolean("flag", false); }