I have a base class for my all of activities (ActivityBase) that itself derives from android.app.Activity. In onCreate I want to execute some conditional logic based on the currently executing child class. If SomeCustomActivity and AnotherCustomActivity both extend ActivityBase, how can I determine in the parent class (ActivityBase) which of the two is the currently executing one?
I have a base class for my all of activities ( ActivityBase ) that
Share
Use instanceof operator.
Supposing you have a base class and two subclasses named
Base,SubOneandSubTwo, if you want to check if a variablerefis an instance ofSubOneorSubTwoyou’d say:Note that:
(ref instanceof Base)will always returntruethough.