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
  • 46,262
  • 29
  • 163
  • 256
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
  • 744
  • 4
  • 17
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,489
  • 2
  • 13
  • 26
0

You can try this:

@Override
 public void onBackPressed() {
 return;
 }

Hope this helps you out !

Apoorv Mehrotra
  • 577
  • 4
  • 13