java 带有多个应用程序标签的 AndroidManifest.xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7491279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AndroidManifest.xml with multiple application tags
提问by Nicknack1016
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.
我对 Android 编程非常陌生,我一直在试图弄清楚为什么我的应用程序在单击按钮时会强制关闭。我把它缩小到几件事。
One question; Is it possible to have more than one <application>
tag in the manifest xml?
一个问题; <application>
清单 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.
我一直在研究,但只发现了一篇关于为新应用程序创建新清单文件的模糊帖子。MyApp 应用程序只是一个用于“全局变量”的应用程序,因为我猜没有新应用程序就无法做到这一点。
Here is the code for MyApp in case it helps:
这是 MyApp 的代码,以防万一:
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.
任何帮助将非常感激。
回答by Marcin Pietraszek
According to documentationmanifest file with only oneapplication element is valid.
根据文档清单文件,只有一个应用程序元素是有效的。
Only the <manifest> and <application> elements are required, they eachmust be present and can occur only once.
只需要 <manifest> 和 <application> 元素,它们都必须存在并且只能出现一次。
回答by ccheneson
What I think you want is to use your custom Application
as the main Application
.
我认为您想要的是使用您的自定义Application
作为主要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>
而只是将它的名称指定给主<application>
(你需要指定它的完整包)。
<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
在这里查看信息
回答by Niket K
Only the 'manifest' and 'application' elements are required, they each must be present and can occur only once. Most of the others can occur many times or not at all — although at least some of them must be present for the manifest to accomplish anything meaningful.
只需要'manifest' 和'application' 元素,它们都必须存在并且只能出现一次。大多数其他人可能会出现多次或根本不会出现——尽管至少其中一些必须存在,清单才能完成任何有意义的事情。