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.
Asked
Active
Viewed 3,000 times
-1
-
5I 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 Answers
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
-
-
already paste this code after oncreate. but still i can use my back button. – Fadzhli Azmandin Jun 21 '13 at 04:43
-
make sure, there is no code inside it. and also this supports only api level 5 and above. – amalBit Jun 21 '13 at 04:46
-
-
still the code did not work after changing the minimum api level – Fadzhli Azmandin Jun 21 '13 at 08:33
-
-
can i have your personal email as i have a lot of question to ask about phonegap on android. – Fadzhli Azmandin Jun 24 '13 at 04:28
-
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
-
-
-
I paste this code on my java files. Can you assist me on where is the right place to paste it ? – Fadzhli Azmandin Jun 21 '13 at 04:38
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.
-
I already use override method but still my i can use my back button. This is so frustrating – Fadzhli Azmandin Jun 21 '13 at 09:02