Manoj Tarkar
Manoj Tarkar

Reputation: 452

Can i use two classes that extends Application?

I have MyApplication.java class that extends Application but when i use a library .aar that also have a Global.Java class extends Application. I have update my menifest file with

<application
        android:name=".activity.MyApplication"

But have got following error:

Caused by: java.lang.ClassCastException: com.xxx.xxx.activity.MyApplication cannot be cast to com.xxx.utils.GlobalClass

Is there anyone who face the same? please help.

Upvotes: 0

Views: 523

Answers (2)

Arpit Ratan
Arpit Ratan

Reputation: 3026

Even if you have two classes which extends from application you can only specify one of them under the application tag. Hence answer to your original question, you cannot have two application classes actually.

To solve your problem you can extend from GlobalClass, your problem would be solved because Global class is inheriting from Application and you are inheriting from GlobalClass.

MyApplication IS-A GlobalClass

GlobalClass IS-A Application

Hence MyApplication IS-A Application.

Upvotes: 1

Naveen Tamrakar
Naveen Tamrakar

Reputation: 3339

According to documentation manifest file with only one application element is valid.

Only the and elements are required, they each must be present and can occur only once.

Upvotes: 1

Related Questions