ProgressDialog disappears when you press the Search key on your phone

In onCreate activity, we connect to a remote system and upload data. All this time we show the canceled ProgressDialog. Downloading is done using AsyncTask. In preExecute () we show the dialog, and in postExecute () we reject it.

The problem is that when you start the download and the ProgressDialog indicator, if the user clicks the Search button on the device, the ProgressDialog disappears. The background thread is still running.

What is the reason for this behavior? How can this be avoided?

Please, help.

thank.

+3
source share
1 answer

( , ):

.setOnKeyListener(new DialogInterface.OnKeyListener() {

    @Override
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
            return true; // Pretend we processed it
        }
        return false; // Any other keys are still processed as normal
    }
})

, , , true . , ...

PS: , "", , . , -, . - ?

PS2: ProgressDialog (Android)

0

Source: https://habr.com/ru/post/1757381/


All Articles