On screen keyboard not closing on Android

Hi, I have some code on Android which basically does the following:

AlertWindow *p_alert = new AlertWindow( title, "Please enter filename", AlertWindow::AlertIconType::NoIcon );

p_alert->addTextEditor( "Filename", "" );
auto p_editor = p_alert->getTextEditor( "Filename" );

p_alert->enterModalState( true, ModalCallbackFunction::create( [ = ]( int res ) {
    String filename = p_editor->getText();
    // do stuff

    // close the filename entry dialog and keyboard
    delete p_alert;

    if ( res ) {
        // do save
        FileChooser *p_fc = new FileChooser( title, File::getCurrentWorkingDirectory().getChildFile( named_file.getFileName() ), filter, true );
        
        p_fc->launchAsync (FileBrowserComponent::saveMode | FileBrowserComponent::canSelectFiles,
                           []( const FileChooser& fc ) {
                           }, nullptr, file_to_write );
    }

This behaves as expected on iOS and when the alert window is deleted on ok or cancel, the onscreen keyboard is also dismissed. However, on Android the keyboard remains. Not sure if this is a bug or whether I should be doing something else before deleting the alert window?

thx

I’m gonna have a look at this one some more later, in the meantime can you try adding
Component::unfocusAllComponents(); before delete p_alert; ?

Hi, yes - that fixes the issue - thanks.

Okay, ideally you would not have to do it manually, there is probably a way to improve it on our side.

2 Likes