AndroidManifest.xml with multiple application tags

15,409

Solution 1

What I think you want is to use your custom Application as the main Application.

So you dont add a new <application> but just specify its name to the main <application>(you need to specify its full package).

<application android:icon="@drawable/icon" android:label="@string/app_name" android:name:"com.mypackage.MyApp"> <!-- Added the android: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="Result" android:label="@string/app_name">        </activity>
</application>

See info here

Solution 2

According to documentation manifest file with only one application element is valid.

Only the <manifest> and <application> elements are required, they each must be present and can occur only once.

Share:
15,409

Related videos on Youtube

Nicknack1016
Author by

Nicknack1016

Updated on June 04, 2022

Comments

  • Nicknack1016
    Nicknack1016 almost 2 years

    I'm very new to Android programming and I've been trying to figure out why my app is force-closing on a button-click. I've narrowed it down to a few things.

    One question; Is it possible to have more than one <application> tag in the manifest xml?

    Here is my code:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.dummies.android.beergoggles"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    
    <application android:icon="@drawable/icon" 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="Result" android:label="@string/app_name">        </activity>
    </application>
    <application android:name="MyApp" 
       android:icon="@drawable/icon" 
       android:label="@string/app_name2"></application>
    

    I've been researching, but found only a vague post about creating a new manifest file for a new application. The MyApp application is just an app for a "global variable", since I guess there's no way to do that without a new application.

    Here is the code for MyApp in case it helps:

    import android.app.Application;
    
    public class MyApp extends Application{
    
    public static int resultCount;
    
    public int getCount(){
        return resultCount;
      }
    public void setCount(int c){
        resultCount = c;
    }
    }
    

    Any help would be much appreciated.