具有多个应用程序标签的 AndroidManifest.xml
我对 Android 编程非常陌生,我一直在试图找出为什么我的应用程序在单击按钮时强制关闭。我已将范围缩小到几件事。
一个问题;清单 xml 中是否可以有多个
标记?
这是我的代码:
<?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>
我一直在研究,但只发现了一篇关于为新应用程序创建新清单文件的模糊帖子。 MyApp 应用程序只是一个“全局变量”的应用程序,因为我想如果没有新的应用程序就无法做到这一点。
这是 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;
}
}
任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据文档清单文件只有一个 应用程序元素有效。
According to documentation manifest file with only one application element is valid.
我认为您想要的是使用自定义
Application
作为主要Application
。因此,您不需要添加新的
,而只需为主
指定其名称(您需要指定其完整包)。请参阅此处的信息
What I think you want is to use your custom
Application
as the mainApplication
.So you dont add a new
<application>
but just specify its name to the main<application>
(you need to specify its full package).See info here
仅需要“manifest”和“application”元素,它们都必须存在并且只能出现一次。其他大多数可能会出现很多次,或者根本不会发生——尽管至少其中一些必须出现才能完成任何有意义的任务。
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.