How to reference the current or main activity from another class

后端 未结 13 805
难免孤独
难免孤独 2021-01-30 12:39

I often find myself needing to access methods that require referencing some activity. For example, to use getWindowManager, I need to access some Activity. But ofte

13条回答
  •  野的像风
    2021-01-30 12:58

    Passing context is better way for refrence Activity.

    You can pass Context to another class.

    IN Activity ::

    AnotherClass Obj  = new AnotherClass(this);
    

    IN Another Class

    class AnotherClass{
    
    public AnotherClass(Context Context){
    
        }
    
    }
    

提交回复
热议问题