Harry
Harry

Reputation: 23

Android Application name Issue

My objective:

  1. Integrate an open source todoapplication as a library app into my main application.

Steps I have completed:

  1. Configured the todoapp as a library project by clicking Islibrary function.
  2. Added the library to my main project.
  3. 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.

Upvotes: 2

Views: 852

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006554

If the library project has a custom Application class, you will need to inherit from its custom Application class when you define yours. So, have WishApplication extends ToDoApplication, instead of WishApplication extends Application.

Note that using a custom Application is frequently pointless. It has the same effective scope as static data members, and there can only be one Application object. Hence, I recommend avoiding using a custom Application class in libraries, as you cannot have two libraries both demanding that the host application use their custom Application class. And, for your own code, only use a custom Application class when it is somehow clearly superior to just an ordinary static data member.

Upvotes: 4

Related Questions