How to add two android:name attributes

1.4k views Asked by At

My current AndroidManifest contain Sugar ORM declaration as follow

<application
    android:name="com.orm.SugarApp"

as stated in their documentation at http://satyan.github.io/sugar/getting-started.html. and it is included as jar library.

and now i need to add declaration for a global variable as illustrated here Android global variable which neeed to add

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

to existing application section. but this means two application sections or two "android:name" which is totally wrong. How to implement this scenario of two applications parts

2

There are 2 answers

1
romtsn On BEST ANSWER

All you need is just extends com.orm.SugarApp in your MyApplication class like this:

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;
    }
}

And the use your MyApplication in the manifest:

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

If u want to use sugar-orm and multidex both as android:name,u can refer below example.

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);
  }
}

Here I extended MyApplication with com.orm.SugarApp and inside this Multidex is installed and next part is include MyApplication in android:name="MyApplication" in Application tag as shown below

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