【问题标题】:How to add two android:name attributes如何添加两个 android:name 属性
【发布时间】:2015-01-27 22:11:54
【问题描述】:

我当前的 AndroidManifest 包含如下糖 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”是完全错误的。如何实现这两个应用部分的场景

【问题讨论】:

    标签: android sugarorm


    【解决方案1】:

    您所需要的只是在您的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;
        }
    }
    

    并且在清单中使用您的MyApplication

    <application android:name="MyApplication" android:icon="@drawable/icon" android:label="@string/app_name">
    

    【讨论】:

    • 这是真的吗,即使 SugarApp 是来自 JAR 文件的库。我应该删除 android:name="com.orm.SugarApp" 并只保留 android:name="MyApplication"
    【解决方案2】:

    如果你想同时使用sugar-orm和multidex作为android:name,你可以参考下面的例子。

    import android.content.Context;
    import android.support.multidex.MultiDex;
    import com.orm.SugarApp;
    
    public class MyApplication extends SugarApp {
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
      }
    }
    

    这里我用 com.orm.SugarApp 扩展了 MyApplication 并在里面安装了这个 Multidex,下一部分是在 Application 标签中的 android:name="MyApplication" 中包含 MyApplication,如下所示

    <application
      ----------
      ----------
      android:name="MyApplication"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 2013-06-05
      • 2014-03-10
      • 1970-01-01
      相关资源
      最近更新 更多