0

I'm developing some android application .In application i want to disable home button .
So i tried to overide onAttachedToWindow method, but the problem is i getting a error when start application.

Code :

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

Error :

java.lang.IllegalArgumentException: Window type can not be changed after the window is added. at android.os.Parcel.readException(Parcel.java:1603) at android.os.Parcel.readException(Parcel.java:1552) at android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:912) at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5415) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1581) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

any one have idea , what is the error of this code ?

Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44

2 Answers2

1

I found the answer for my question . in android Lolipop have startLockTask() funciton.this will pin your task. thak you all .

0

As I mentioned in other question, you are not able to disable or override, or even detect home button. Set type of window you can only before setContentView().

Tomasz Czura
  • 2,414
  • 1
  • 14
  • 18
  • hi Tomasz , but most of webs and blogs says , this is the method for disable home button.any way ,do you know the way for this ? – Kapila Ranasinghe Jun 23 '16 at 18:09
  • Could you show me some of that webd or blogs? They may be reference to older android SDK's - as I remember, before SDK 14 it was possible that way. For newer version's you can't disable home (for security reasons - imagine, that somebody block your home and you can not do anything with your phone). Could you tell me why do you try to do this? Maybe there is a better way to accomplish your purpose – Tomasz Czura Jun 23 '16 at 18:12
  • https://developer.zebra.com/thread/1163 , http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key , this references says above technique for disable home button. but my min SDK version is 15 . so i can understand now the reason. – Kapila Ranasinghe Jun 23 '16 at 18:19