What does this 4-line java code mean in an Android app?

In my java application i have this code

@Override public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); super.onAttachedToWindow(); } 

when I create it for Android 2.3 (level 10) , it compiles and works fine. But when I create it for android 4.0 (level 15) , it compiles and gives me a crash at runtime and the following error

 07-16 14:00:03.090: E/AndroidRuntime(29487): FATAL EXCEPTION: main 07-16 14:00:03.090: E/AndroidRuntime(29487): java.lang.IllegalArgumentException: Window type can not be changed after the window is added. 

when I comment on this line and build it, it works fine and not a problem ..

 //this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); 

so I don’t understand why this is happening and what does this code mean?

Edit: some links here

when running the application on my phone. Android Version 4.0.3

secure toddler app on Android phone

+5
java android android-emulator android-windowmanager
Sep 24
source share
3 answers
 @Override public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); super.onAttachedToWindow(); } 

used to disable the home button in android but

this security flaw has been fixed in new versions of Android , so it will not work in ICS and jelly bean ... !!

+9
Oct. 15 '12 at 7:07
source share

I solved this problem by setting

 this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); 

in onCreate before calling super.

  protected void onCreate(Bundle savedInstanceState) { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); super.onCreate(savedInstanceState); } 

Saludos desde medellΓ­n

+4
Nov 14 '13 at 18:26
source share
 @Override public void onWindowFocusChanged(boolean hasFocus) { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); super.onWindowFocusChanged(hasFocus); } 

I had some problems with windowAttached, try using windowFocusChanged instead.

+2
Sep 24 '12 at 7:02
source share



All Articles