-2

Possible Duplicate:
Disable back button in Android(Not working)

I am using the default camera in my app(The inbuilt-camera feature of Android). I have tried using

 public void onBackPressed() {

    }

but instead of blocking the back button, the app hangs forcing the user to terminate the app/restart it.

Community
  • 1
  • 1
onkar
  • 109
  • 1
  • 2
  • 11

2 Answers2

1

try this . it's work for me in activity .

 // Disable Device Back Button
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    // TODO Auto-generated method stub
    if ((keyCode == KeyEvent.KEYCODE_BACK)) 
    {
        return false;
    }
    return super.onKeyDown(keyCode, event);
}// end of disable back event

So try This aslo .

 @Override public void onBackPressed()
 {
 // TODO Auto-generated method stub
  super.onBackPressed();
   finish(); 
 }

i am using this code and run perfectly for me edit your code once and get back me.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) 
{
Bitmap photo = (Bitmap) data.getExtras().get("data"); 
Button btnCaptureAgain=(Button)findViewById(R.id.btnCaptureAgain);
Button btnRemove=(Button)findViewById(R.id.btnRemove);
Drawable dr = new BitmapDrawable(photo);
imgCamera.setBackgroundDrawable(dr);
rltvbtngone.setVisibility(View.VISIBLE);
btnCaptureAgain.setOnClickListener(ctrlAddImageCamera.btnCaptureAgain);
btnRemove.setOnClickListener(ctrlAddImageCamera.btnRemove);
}
super.onActivityResult(requestCode, resultCode, data);
}
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
  • Please find it [here](http://stackoverflow.com/questions/13191946/disable-back-button-in-androidnot-working) – onkar Nov 03 '12 at 05:23
1

You must override that method

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
          //Your action on press back here
          return true;
        default:
            return super.onKeyDown(keyCode, event);
    }
}
Andrew
  • 266
  • 6
  • 18