Get child class name from parent

前端 未结 6 582
广开言路
广开言路 2021-02-06 21:36

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 conditio

6条回答
  •  [愿得一人]
    2021-02-06 22:09

    I think you want to use the instanceof operator, for example:

    if(this instanceof SomeCustomActivity) {
        // do stuff
    } else if (this instanceof AnotherCustomActivity) {
        // do other stuff
    }
    

    And that is all there is to it.

提交回复
热议问题