android - 如何添加两个android :name attributes

标签 android sugarorm

我当前的 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/

相关文章:

android - 制作像 Discord 这样的多平台应用程序的技巧

android - Android Studio Build Process不会完全删除xml中的 View 吗?

android - 错误 : type SugarRecord does not take parameters

android - 如何使用带有@Table注解的satyan的Sugar ORM

android - Sugar ORM 中的 SugarContext.init(this) 是什么

java - 在弹出窗口中切换 NullPointerException

android - CoordinatorLayout、AppBarLayout 和 ToolBar - 工具栏不会滚出屏幕

android - 电源按钮行为。 onPause > onResume > onPause 被调用

android - 没有这样的表 Sugar ORM