My objective:
- Integrate an open source todoapplication as a library app into my main application.
Steps I have completed:
- Configured the todoapp as a library project by clicking Islibrary function.
- Added the library to my main project.
- Added all the activities of the library project with their full package names in my main android manifest file as per this link.
Issue Faced:
I am getting a runtime error and there are no comilation errors and the library project is integrated perfectly.
Root Cause:
When I analyzed Logcat, I understand it is due to application name conflict. My main app has an application name as “wish” in its manifest file. The library project in its manifest file also has a name as “Todoapplication”
In the java file there is a line of code as below:
m_app = (TodoApplication) getapplication();
This line throws run time exception because in the main manifest file there is no Todoapplication in the name parameter.
Can anyone, please help me on the situation. Thanks.
If the library project has a custom
Applicationclass, you will need to inherit from its custom Application class when you define yours. So, haveWishApplication extends ToDoApplication, instead ofWishApplication extends Application.Note that using a custom
Applicationis frequently pointless. It has the same effective scope as static data members, and there can only be oneApplicationobject. Hence, I recommend avoiding using a customApplicationclass in libraries, as you cannot have two libraries both demanding that the host application use their customApplicationclass. And, for your own code, only use a customApplicationclass when it is somehow clearly superior to just an ordinary static data member.