带有多个应用程序标签的AndroidManifest.xml [英] AndroidManifest.xml with multiple application tags
问题描述
我对Android编程非常陌生,而且我一直试图找出为什么我的应用程序在按下按钮时强行关闭。我把它缩小到了几个方面。
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.
一个问题;清单xml中是否可以有多个< application>
标记?
One question; Is it possible to have more than one <application>
tag in the manifest 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应用程序只是一个全局变量的应用程序,因为我猜没有新的应用程序就没有办法做到这一点。
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:
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.
推荐答案
我认为您想要的是使用您的自定义应用程序
作为主申请
。
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 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>
查看信息这里
这篇关于带有多个应用程序标签的AndroidManifest.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!