-2

There is a process that lasts 2 seconds, during the process I need to lock the entire screen and the buttons of the mobile phone. There is a code that disables only the cancellation process.

public void onClick(View view) {
    int pos = getAdapterPosition();
    dialog= new ProgressDialog(context);
    dialog.setMessage("Please wait ...");
    dialog.setCancelable(false);
    dialog.show();


    if(pos != RecyclerView.NO_POSITION){
        LanguageRecycler clickedDataItem = mData.get(pos);
        SharedPrefManager.getmInstance(context).setCity(clickedDataItem.getAlias());

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                ((Activity)context).finish();

            }
        }, 2000);
    }
}
Fábio Nascimento
  • 2,479
  • 1
  • 20
  • 26
Muza Rasulov
  • 11
  • 1
  • 5
  • add xml file also – Ram Mohan dubey Feb 19 '19 at 09:46
  • And now does the code work? If not what error do you get? ... Please put some more effort in a question - and ask a question – Hille Feb 19 '19 at 09:46
  • You can lock your own app, but you can't lock the entire screen AND the buttons of the phone itself. How would you like if it another app did that to you? You shouldn't lock your own app, either - apps should be responsive. – S.L. Barth Feb 19 '19 at 09:47
  • @Muza Rasulov has to look at this [answer](https://stackoverflow.com/questions/10077905/override-power-button-just-like-home-button) first. – Tanveer Munir Feb 19 '19 at 10:16

2 Answers2

-2

This will disable the button

    Button myButton = findViewById(R.id.button);
    myButton.setEnabled(false) 
-2

Try this one

@Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_BACK) {
        //do something or nothing here
      return true;
      }
     return super.onKeyDown(keyCode, event);    
   }