我当前的 AndroidManifest 包含 Sugar ORM 声明如下
<application
android:name="com.orm.SugarApp"
如他们在 http://satyan.github.io/sugar/getting-started.html 的文档中所述.它作为 jar 库包含在内。
现在我需要为全局变量添加声明,如此处所示 Android global variable需要添加
application android:name="MyApplication" android:icon="@drawable/icon" android:label="@string/app_name">
到现有的应用程序部分。 但这意味着两个应用程序部分或两个“android:name”,这是完全错误的。如何实现两个应用程序部分的场景
最佳答案
您所需要的只是在您的 MyApplication
类中扩展 com.orm.SugarApp
,如下所示:
public class MyApplication extends com.orm.SugarApp {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onTerminate() {
super.onTerminate();
}
private String someVariable;
public String getSomeVariable() {
return someVariable;
}
public void setSomeVariable(String someVariable) {
this.someVariable = someVariable;
}
}
然后在 list 中使用您的 MyApplication
:
<application android:name="MyApplication" android:icon="@drawable/icon" android:label="@string/app_name">
关于android - 如何添加两个android :name attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27202413/