I often have to deal with a similar error when programming in Java on Android. For example, I have a class where I set the flag.
public class ViewActivity extends Activity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
...
}
In another class, I want to reset FLAG_KEEP_SCREEN_ON
class DrawOnTop extends View {
...
if (condition) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
but this does not work since I get the "getWindow method undefined for type DrawOnTop".
So, I'm trying to define a clearFlags method in the ViewActivity class
void clearFlags() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
and call it from the DrawOnTop class:
if (condition) {
ViewActivity.clearFlags();
}
This does not work: I get "Can't make a static reference to the non-static clearFlags () method of type ViewActivity." Well, let it be static then.
static void clearFlags() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
and then I get "Can't make a static reference to the non-static getWindow method from type Activity"
How can I fulfill this statement?