[FIXED] How to call getWindow() outside an Activity in Android?


I am trying to organize my code and move repetitive functions to a single class.
This line of code works fine inside a class that extends activity:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

However it is not working when I try to include it into an external class.

How do I call getWindow() from another class to apply it inside an Activity?


Pass a reference of the activity when you create the class, and when calling relevant methods and use it.

void someMethodThatUsesActivity(Activity myActivityReference) {
    myActivityReference.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Answered By – MByD

Answer Checked By – David Goodson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published