how to handle multiple application classes in android

user2072344 picture user2072344 · Sep 25, 2013 · Viewed 17k times · Source

I am developing a native android application, in which I am trying to use 2 open-source libraries. Problem is both the libraries are using Application Class in their respective libraries. They are registering these classes in their respective source code in manifest file using "android:name" under the application tag. Question is how to handle such a scenario, since as we know, only ONE tag can be used inside manifest file. Can we register/instantiate the Application Class in the code, so that we mention only ONE library in tag and the second using code/pragmatically. OR are there any other alternatives. Please share your comments/suggestions. Thanks in advance.

Answer

Biraj Zalavadia picture Biraj Zalavadia · Sep 25, 2013

You need to implement Multilevel inheritance to resolve this scenario.

This is your scenario

public Lib1Application extends Application{

}

public Lib2Application extends Application{

}

public YourApplication extends Application{

}

How to resolve this?

public Lib1Application extends Application{

    }

    public Lib2Application extends Lib1Application{

    }

    public YourApplication extends Lib2Application{

    }

finally in mainfest.xml

<application
        android:name="com.your.packagename.YourApplication"
        android:icon="@drawable/ijoomer_luncher_icon"
        android:label="@string/app_name"
 >