Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidManifest.xml with multiple application tags

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.

like image 617
Nicknack1016 Avatar asked Sep 20 '11 20:09

Nicknack1016


2 Answers

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.

like image 93
2 revs, 2 users 83% Avatar answered Oct 13 '22 19:10

2 revs, 2 users 83%


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

like image 41
ccheneson Avatar answered Oct 13 '22 19:10

ccheneson