1

In my android application.

I am opening one web page using webview. So at that time I want to disable physical back button of mobile. please anybody help?

here i tried.

  1. onbackpressed() function.

in my activity class, i have written, @Override public void onBackPressed() {

}

but didn't work.

4 Answers4

1

Just don't call the super class:

@Override
public void onBackPressed() {
    if(allowedToClose) {
        super.onBackPressed();
    }
}
rekire
  • 47,260
  • 30
  • 167
  • 264
0

If you want that nothing happens on pressing back button , just leave the onBackPressed function empty.

Remember to delete super.onBackPressed(); also.By default , it is there in the function.

schinj
  • 794
  • 4
  • 19
0

You can declare global variable disableEvent by

final boolean disableEvent;

Your Preexecute method can set it to false by

disableEvent = false;

Your Postexecute method can set it to true by

disableEvent = true;

Now override onBackPressed as:

@Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        if (disableEvent)
        {
            // do nothing
        }
        else
        {
            // do something
        }
    }
Deep Patel
  • 2,584
  • 2
  • 15
  • 28
0

You can try this:

@Override
 public void onBackPressed() {
 return;
 }

Hope this helps you out !

Apoorv Mehrotra
  • 607
  • 5
  • 13