1

All I want is to block home button when my app is running

            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" >
            </category>
        </intent-filter>

I have written the above code in manifest when i start my app for the first time and i press home button it ask me to set my app or default mobile app to be set as default for home.. Once i select the default something other than my app and check the always checkbox.. The next time I start my app this dialog box never appears..

public void onAttachedToWindow() {
        window.setType(LayoutParams.TYPE_KEYGUARD|LayoutParams.FLAG_FULLSCREEN|LayoutParams.FLAG_LAYOUT_IN_SCREEN|LayoutParams.FLAG_KEEP_SCREEN_ON);

        super.onAttachedToWindow();
    }

Do not work in Android 4.0 and above

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
  • You can't and should not do that. The home button always uses the system defined behaviour and is not for use as a means of navigation in your app. – Thrakbad Jan 30 '13 at 12:19
  • Check this Link http://stackoverflow.com/questions/10025660/override-home-and-back-button-is-case-a-boolean-is-true/10025904#10025904 – Miral Dhokiya Jan 30 '13 at 12:28

1 Answers1

1

You cannot override home button for Android4.0 onwards due to security reasons, to enable the user exit in case the application turns out to be a malware.

Plus, it is not a really good practice to not let the user navigate away from the application. But, if your application requires so, what you can do is declare the activity as a Launcher , so that when the HomeButton is pressed it will simply restart your application and remain there itself

vinuonline
  • 143
  • 2
  • 3
  • 14
  • How does the Toddler Lock work on Android 4.0... I am able to bring up the change default dialog once but second time when my app starts it do not work.. you may dialog that i am talking about in http://android.stackexchange.com/questions/17128/how-to-change-a-default-application-in-ice-cream-sandwich – user1999564 Jan 30 '13 at 13:14
  • Home button cannot be overriden. You can write an application that responds to the home intent (that's what a launcher does) but that's all. – vinuonline Jan 31 '13 at 04:19
  • I am ok with it.. The only problemis it appear only once and then from next time it simply do not appear once something other than my app is set as default.. – user1999564 Feb 01 '13 at 07:17