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

You shall not keep references around as suggested in the accepted answer. This works, but may cause memory leaks.

Use this instead from your view:

((Activity) getContext()).getWindow()...

You have a managed reference to your activity in your view, which you can retrieve using getContext(). Cast it to Activity and use any methods from the activity, such as getWindow().

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)