1

I want to change my first activity, first I have activity named MainActivity. And I add new activity named ActivityFirst. Surely I have to change AndroidManifest.xml. Previously I have androidManifest like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="edmt.dev.androidsimsimi">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        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>
    </application>

</manifest>

And after I add my new activity, also I change my androidManifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="edmt.dev.androidsimsimi">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".ActivityFirst">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

I'm confused where I put the MainActivity after I add ActivityFirst. This my ActivityFirst.java:

public class ActivityFirst extends AppCompatActivity {

  private Button mulai;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first);

    mulai = (Button) findViewById(R.id.mulai);

    mulai.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(ActivityFirst.this, MainActivity.class);
            startActivity(intent);
        }
    });
  }
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
syaifulhusein
  • 269
  • 2
  • 8
  • 18
  • maybe this is a helpful link? [Link](https://stackoverflow.com/questions/3631982/change-applications-starting-activity#3632061) – PMiner Jul 07 '17 at 01:57

2 Answers2

6

You need <activity> tags for each Activity in your app's manifest file as mentioned here in the docs:

All activities must be represented by elements in the manifest file. Any that are not declared there will not be seen by the system and will never be run.

So in your case, it'd be like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="edmt.dev.androidsimsimi">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".ActivityFirst">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
DaveNOTDavid
  • 1,753
  • 5
  • 19
  • 37
1

In Android, The first Activity to show when a app is launched is tagged LAUNCHER in your manifest file.

All you need do to change the Launcher Activity is to add an intent-filter tag inside the activity tag.

So if your activity tag was self closing, you change it and add intent filter tag inside the tag.

Here is an illustration.

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

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

The above code in your Manifest will make ActivityFirst the launcher activity,

while the below code will make MainActivity the launcher activity.

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

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

I hope this helps.