以简单的方式访问 getWindow 方法 java class

Acess getWindow method in simple java class

我在 Activity class 中使用方法 Window wingdow = getWindow()。现在我想在简单 java class 中使用此方法,但它会出错 not resolve method。我也使用 context 但它也有错误。我们怎样才能简单地访问它 java class.

创建实例传递 Activity 作为构造函数的参数

MyClass myClass= new MyClass(this);

并像这里一样使用getWindow()方法

public Class MyClass
 {
    public Activity activity;
    public MyClass(Activity act)
    {
         this.activity = act;

    }
   public void otherMethod(){
      Window window = act.getWindow()
   }
 }