0

I can run this code in my computer:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  

inside onResume(). I sent the code to someone else for testing. But they tell me that that this line shows an error in their SDK, and replacing it with

getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  

works, while in my case, both the codes work. Why is this happening?

PS: My SDK version is the one with the zip file name adt-bundle-windows-x86-20130522. I am not sure the exact version they are using, but it is newer than mine.

user13267
  • 6,871
  • 28
  • 80
  • 138

1 Answers1

2

WindowManager is a class in the Android SDK. Its fully qualified name is android.view.WindowManager. The WindowManager.LayoutParams is a nested class of WindowsManager and its fully qualified name is android.view.WindowManager.LayoutParams

You can either specify the fully qualified name when you want to use it.

getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  

or you can import its outer class

import android.view.WindowManager;

and use it directly

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • both of our codes are exactly the same, so how can I make it so that they don't have to add android.view ? – user13267 Oct 10 '13 at 01:30
  • @user13267 Use the `import` statement before your class declaration. – Sotirios Delimanolis Oct 10 '13 at 01:31
  • `import android.view.WindowManager;` is present, otherwise it doesn't compile even on my SDK – user13267 Oct 10 '13 at 02:23
  • @user13267 Can you please edit your question and add the code that doesn't compile and give us the compilation error? – Sotirios Delimanolis Oct 10 '13 at 02:26
  • I am sorry but the error occurs in the other person's computer and all they told me was that it doesn't compile unless we use `android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON` inside `addFlags()'. In my case it works either way. – user13267 Oct 10 '13 at 02:40
  • @user This depends on the error. Have they added the `import`? Is the Android SDK on the classpath? – Sotirios Delimanolis Oct 10 '13 at 02:41
  • the code file is exactly same as mine so they have the import as well, but I am not sure about the classpath. How can I check about the classpath on my computer? – user13267 Oct 10 '13 at 02:46
  • @user13267 A classpath is different for every Java application and is set with the `-cp` flag. If you are using an IDE like eclipse you can check in the `Java Build Path` in the project properties. – Sotirios Delimanolis Oct 10 '13 at 02:47
  • I can see four tabs, Source, Project, Libraries and Order and Export. How do I check (in my computer) if Android SDK is on the classpath? – user13267 Oct 10 '13 at 02:51
  • @user It would normally be under `Libraries` with a name like `Android SDK X`. – Sotirios Delimanolis Oct 10 '13 at 02:52
  • There are three options: Android 4.3, Android Dependencies and Android private libraries. Each is a tree root (that is, each has a + sign next to it), but I can't find anything of the format `Android SDK X` in any of the sub branches – user13267 Oct 10 '13 at 02:54
  • @user No, what you have seems fine. Does the other computer also have that? – Sotirios Delimanolis Oct 10 '13 at 02:55
  • I am sorry but right now I cannot say what the computer might have at that place, but I am sure they are all left at the default values. Could this be the point that is causing the error at their computer but not at mine? – user13267 Oct 10 '13 at 04:15
  • @user13267 I don't think so. If it was, putting the fully qualified name wouldn't work either. It's probably an error in the `import` statement. The compilation error will give you more details when you can get it. – Sotirios Delimanolis Oct 10 '13 at 04:16
  • ok if they provide me the compilation error I will post it here. Thank you very much for your help and time. – user13267 Oct 10 '13 at 04:19
  • @user You're welcome. If you want you can post it here, but consider also posting a new question with all the relevant information if you find the question is unrelated to this one. – Sotirios Delimanolis Oct 10 '13 at 04:20