-1

I really want a straight forward answer as I always on the dead end. How to disable back button ( the hardware back button ) and where did I need to write the code to disable it ? I just want user of my apps to use the navigation on my apps.

  • 5
    I hope you have a good reason to disable it. Users hate it when things don't work like they expect, like not having a back button. – Mike Park Jun 21 '13 at 04:22
  • You can override the `onBackPressed()` method on your activities to suppress the back button behavior, but you really shouldn't do this. If you can't architect your app in a way that allows using the back button, I suggest you re-think your app's navigation. – Karakuri Jun 21 '13 at 04:25
  • https://www.google.co.in/search?q=How+to+disable+back+key+button+in+Android&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=rcs.............. plz use google – Sam Jun 21 '13 at 04:25
  • @climbage i'am making an online radio apps. so there will be no need for user to use the back button. the user can navigate it using the apps. – Fadzhli Azmandin Jun 21 '13 at 04:40

3 Answers3

3

after your onCreate just:

    @Override
    public void onBackPressed() {

    } 

Now if you want to do anyUpdate before backButton:

      @Override
   public void onBackPressed() {
      //your function that updates
    } 

Api :

Go to your manifest and see the tab, the minimumSDK there should be 5.

SDK_INT value        Build.VERSION_CODES        Human Version Name       
1                    BASE                    Android 1.0
2                  BASE_1_1                  Android 1.1
3                   CUPCAKE                  Android 1.5 Cupcake
4                    DONUT                   Android 1.6 Donut
5                   ECLAIR                   Android 2.0 Eclair
6                   ECLAIR_0_1               Android 2.0.1 Eclair                  
7                   ECLAIR_MR1               Android 2.1 Eclair
8                   FROYO                    Android 2.2 Froyo
9                  GINGERBREAD               Android 2.3 Gingerbread
10                  GINGERBREAD_MR1           Android 2.3.3 Gingerbread
11                  HONEYCOMB                 Android 3.0 Honeycomb
12                  HONEYCOMB_MR1             Android 3.1 Honeycomb
13                  HONEYCOMB_MR2             Android 3.2 Honeycomb
14                  ICE_CREAM_SANDWICH        Android 4.0 Ice Cream Sandwich
15                  ICE_CREAM_SANDWICH_MR1    Android 4.0.3 Ice Cream Sandwich
16                  JELLY_BEAN                Android 4.1 Jellybean
17                  JELLY_BEAN_MR1            Android 4.2 Jellybean
10000                CUR_DEVELOPMENT           Current Development Build
amalBit
  • 12,041
  • 6
  • 77
  • 94
1

Override the onKeyDown method within the activiy where you want to disable back key.

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KEYCODE_BACK) {
        return true;
    return false;
}

Note that returning true from onKeyDown will disable the default behavior

stinepike
  • 54,068
  • 14
  • 92
  • 112
0

What amalBit said is correct.If you have problem in overriding function, In Eclipse press Alt+Shift+S or Source Menu and select Override/Implement Methods and select onBackPressed() method and leave it back.

Community
  • 1
  • 1
Naresh
  • 3,174
  • 1
  • 17
  • 22