简体   繁体   中英

I am having an issue with my AndroidManifest.xml file in activity name

I'm learning to write the notification code for the first time in android and seeing errors in AndroidManifest.xml file with the activity names(as they are appearing red, I guess meaning error) hence, can't run the app.

The error is thrown in the

android:names(yes in all three of them) ,they can't , I believe fetch the information they required.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.aptech.androidservice.androidnotificationexaample"
 android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk android:minSdkVersion="11"
        android:targetSdkVersion="19"/>
    <uses-permission android:name="android.permission.VIBRATE"/>

    <application
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher_background"
        android:label="@string/app_name">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:name=".NotificationActivity"
            android:label="Notification Click Action"
            android:name=".SubNotificationActivity"
            android:label="Sub Notification Click Action">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
<activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:name=".NotificationActivity"
            android:label="Notification Click Action"
            android:name=".SubNotificationActivity"
            android:label="Sub Notification Click Action">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

That's not how you define activities in your app, each activity must have a separate activity tag.

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"/>
    <activity
        android:name=".NotificationActivity"
        android:label="Notification Click Action"/>
    <activity android:name=".SubNotificationActivity"
        android:label="Sub Notification Click Action">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

You are facing this issue because each activity tag can only have one name. Remember xml format is key-value, of which key is UNIQUE, so you have to write multiple tags, like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.aptech.androidservice.androidnotificationexaample"
  android:versionCode="1"
  android:versionName="1.0">
  <uses-sdk android:minSdkVersion="11"
    android:targetSdkVersion="19"/>
  <uses-permission android:name="android.permission.VIBRATE"/>

    <application
      android:allowBackup="false"
      android:icon="@drawable/ic_launcher_background"
      android:label="@string/app_name">
      <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>
    <activity
        android:name=".SubNotificationActivity"
        android:label="Sub Notification Click Action"/>
    <activity
        android:name=".NotificationActivity"
        android:label="Notification Click Action"/>
</application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM