Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this 4 line java code means in android application?

In my java application i have this code

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

when i build it for android 2.3 (level 10) it compiles and works fine. But when i build it for android 4.0 (level 15) it compiles and gives me crash at run time and 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 this line and build it works fine and no issue..

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

so i am not getting why this happning and whats this code means?

Edit : some reference are here

when I run app on my phone.The version is android 4.0.3

toddler safe app on android

like image 954
Jeegar Patel Avatar asked Sep 24 '12 06:09

Jeegar Patel


People also ask

What is Java in Android application?

The platform for app development in Android is Java. This means that you use the Java library and code the applications in Java, C, and C++ programming language. But, the most widely used programming language for android application development is Java.

What is the use of Java in Android application development?

As of now, the main perks of Java for mobile app development range from cross-platform compatibility, constant updates, and open-source to community support and native mobile development tools.

Why is Java needed for Android?

It allows you to write code in html, javascript and css, which can be then used to make Android/iOS/Windows applications. Such apps are called web-apps. It needs just a bit of java to make the application work.


2 Answers

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

is used to disable home button in android but

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

like image 126
Jeegar Patel Avatar answered Sep 30 '22 17:09

Jeegar Patel


I've solved this issue putting

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

like image 40
Alejandro Tamayo Avatar answered Sep 30 '22 16:09

Alejandro Tamayo