-6

I would like to disable home button on android 4.2 to prevent user from closing the application. I read that I can't directly catch home button event on 4.2 so I may need to implement some home screen application?? I was wonder if there is any sample code to simply show this functionality ( Goal is not allowing the user to close the program.maybe rerun the program on key down).

Thanks in advance for the help, Ray

Reza Salehi
  • 11
  • 1
  • 3
  • Hi..Yes but didn't help on 4.2 Jelly bean – Reza Salehi Mar 13 '13 at 21:30
  • Thanks. I had seen that post before but I was wonder if there is any update or workaround to this problem.In that post one possible solution was implementing a home screen. So my question was is there any sample code to demonstrate how to implement home screen? It is also useful if I can rerun my application in case use clicks on hoe button. – Reza Salehi Mar 13 '13 at 21:54
  • Not sure about that, but you might find it easier to override some Key EventHandlers, like this: http://stackoverflow.com/questions/10025660/override-home-and-back-button-is-case-a-boolean-is-true/10025904#10025904 – crazylpfan Mar 13 '13 at 22:20
  • Thanks Man..All these methods work on 2.x and not 4.x versions.So it seems for 4.x there is no straight forward work around to disable/catch home button event – Reza Salehi Mar 13 '13 at 22:33
  • You tried using KeyEvents? You should be able to use them in Android 4.0+. – crazylpfan Mar 13 '13 at 22:36

1 Answers1

3

Make your app be the home screen. Then, pressing HOME will return the user to your app. There is a Home SDK sample in your SDK installation (if you chose to download SDK samples). Basically, you need an <intent-filter> on your activity like:

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491