Dheeraj Bhaskar
Dheeraj Bhaskar

Reputation: 19039

Multiple classes extending Application

two classes extend Application

Note:

Everything is working as it should.

My Question:

Are there any drawbacks of using multiple Application classes? Is this even advised?

A few thoughts:

PS: I know I can just use a field to store context in the second class.

Upvotes: 11

Views: 2861

Answers (1)

Orabîg
Orabîg

Reputation: 11992

I think this is not advised at all, because there is could only be one instance on Application (thus only one class).

I am very suspicious about what is really working. You're talking about utility class, so maybe you're using static methods that are working well. But you should use your debugger, and I'm almost certain that you'll discover that one of your classes is never instantiated.

By the way, the official documentation states that :

" There is normally no need to subclass Application. In most situations, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton. "

Upvotes: 8

Related Questions