shailesh ojha
shailesh ojha

Reputation: 247

Acess getWindow method in simple java class

I am using method Window wingdow = getWindow() in my Activity class. Now i want to use this method in simple java class but it get errors not resolve method. I also use context but it also get erros. How can we access it in simple java class.

Upvotes: 2

Views: 1594

Answers (1)

Shree Krishna
Shree Krishna

Reputation: 8562

Create instance passing Activity as parameter of constructor

MyClass myClass= new MyClass(this);

And use getWindow() method like here

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

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

Upvotes: 4

Related Questions