一个Android应用程序中包含多个应用程序文件 [英] Multiple Application Files in one Android app
问题描述
我制作了三个应用程序,现在我希望将它们打包到一个apk文件中(一个安装程序).在启动包装器应用"时,用户应决定要运行哪个应用.
I made three apps, which I now want to ship in one apk file (one installation). On startup of the "wrapper app" the user should decide which app to run.
到目前为止,还不错,但是问题是,每个应用程序都使用应用程序文件中的全局常量.有没有一种方法可以将三个应用程序合为一个,每个应用程序都使用自己的应用程序文件?
So far, so good, but the problem is, each app is using global constants from an Application file. Is there a way to build the three apps into one, where each app uses its own application file?
谢谢!
为避免混淆,我添加一个简短的示例:
To avoid confusion i add a short example:
应用1:
public class AApplication extends Application {
public static String CONSTANT_1 = "aaa";
}
应用2:
public class BApplication extends Application {
public static String CONSTANT_1 = "bbb";
}
应用3:
public class CApplication extends Application {
public static String CONSTANT_1 = "ccc";
}
推荐答案
好吧,由于我的想法显然无法实现,因此我提出了以下解决方法:
Ok, since the idea I head is obviously not realizable I came up with the following workaround:
-
我在新项目中创建了一个Apllication类
I created an Apllication class in the new Project
public class NewApplication extends OldSuperApplication {}
我添加了一种方法
I added a method
public static void setApplication(RGCApplication a) {
CONSTANT_1 = a.CONSTANT_1;
...
}
在开始屏幕上选择所需的子应用"后,在这种情况下,我会调用"A"应用
after selecting the desired "sub-app" on the startscreen in this case application "A" i call
NewApplication.setApplication(new AApplication());
或
NewApplication.setApplication(new BApplication());
我不确定这是否是臭代码,但可以!
I'm not sure if this is smelly coding or not, but it works!
这篇关于一个Android应用程序中包含多个应用程序文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!