Search code examples
androidandroid-activity

Remove MainActivity created by Android Studio


How can edit the manifest so the MainActivity is removed?

I've been following some tutorials to learn to create android apps and I've got stuck in the Activity subject.

When I create a project the Software gives me an deafult activity called MainActivity. I've deleted it so I could name my class as I wish.

However, even after deleting the files the activity still presents on the Manifest. I've tried to play around, deleting some words, but with no success.

This is the current manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="androidedx.example.activitylifecycle">
<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=".Activity1"></activity>
<activity android:name=".Activity2" />
<activity android:name=".MainActivity">-------<<<<<<0!!!!!!!!!!!!!
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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


    </manifest>

It has this row of content that the android studio warns me about, that I'm poiting with -------<<<<<<0!!!!!!!!!!!!!.

I recall my question: How can edit the manifest so the MainActivity is removed?


Solution

  • Remove the MainActivity Java file and Manifest Declaration and activity1 set as a LAUNCHER Activity

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="androidedx.example.activitylifecycle">
    <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=".Activity1">
     <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Activity2" />
    </application>
    
    
        </manifest>