Declare your new activity in your manifest.xml
To declare a new activity in your Android app's manifest.xml
file, you need to add a <activity>
element inside the <application>
element. Here's an example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<!-- Declare the new activity -->
<activity
android:name=".MyNewActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Other activities, services, and receivers... -->
</application>
</manifest>
Let's break down the elements:
android:name
: specifies the fully qualified name of the activity class, e.g.,com.example.myapp.MyNewActivity
.android:exported
: specifies whether the activity can be launched from outside the app. Set totrue
if you want the activity to be accessible from other apps or from the device's home screen.intent-filter
: specifies the intent filters that the activity responds to. In this example, we're using theMAIN
action andLAUNCHER
category to make the activity the default launcher activity.
Note that you need to create a new Java class that extends the Activity
class and matches the name specified in the android:name
attribute. For example:
public class MyNewActivity extends AppCompatActivity {
// Activity code goes here
}
Make sure to update the AndroidManifest.xml
file and the Java class accordingly, and then rebuild and run your app to test the new activity.