B4J Question UI created by B4J code not responsive when inline java is being executed

BeeriaApps

New Member
Hello all.
I've created UI app which runs some java code (in inline java section). All code (both b4j and java) is in 'main' section.
The problem is, when java method is triggered, UI freezes and is not responsive (until java part is finished). Application works as expected, just doesn't look "professional" because of frozen UI while java is executed.
How to avoid such situation?
Sub which triggers inline java -->
B4X:
Sub btnOpenFW_Click
    btnOpenFW.Enabled = False
    TextAreaMylogs.Text = "Start..."
    Sleep(10)'time to refresh UI before java is executed
    Dim myLogin As String = txtLogin.Text
    Dim myPass As String = txtPassword.Text
    If isPassShown = 0 Then myPass = txtPassword.Text Else myPass = txtPasswordShown.Text
    Dim driverLocation As String
    driverLocation = ((GetSystemProperty("user.home", "").Replace("\", "/")) & "/chromedriver/chromedriver.exe")
    NativeMe = Me
    Dim a As String = NativeMe.RunMethod("FWOpen", Array(myLogin, myPass, driverLocation))
    btnOpenFW.Enabled = True
    TextAreaMylogs.Text = TextAreaMylogs.Text & CRLF & a
End Sub
inline java part
Java:
#If JAVA
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

public static String FWOpen(String myLogin, String myPass, String driverLocation) {
       
        System.setProperty("webdriver.chrome.driver", driverLocation);
        ChromeDriver driver = new ChromeDriver();
        driver.manage().window().setPosition(new org.openqa.selenium.Point(0, 4000));
        driver.manage().window().setSize(new org.openqa.selenium.Dimension(1920, 1200));
        WebDriverWait wait = new WebDriverWait(driver, 10);
//the rest of the code are just interactions with the browser  
}
#End If
found similar topic -->
https://www.b4x.com/android/forum/threads/resumable-subs-with-java-inline-code.80035/#post-506764
but unfortunately my java knowledge is VERY limited and have no idea how to deal with such a problem.
Any help highly appreciated.
 

DonManfred

Expert
Licensed User
Longtime User
I'm not 100% sure what this code does, but based on your description it is slow.
Probably it is related to

A similar Library is this one:
 
Upvote 0

BeeriaApps

New Member
DonManfred you are right. Unfortunately b4x selenium library does not exist any more (no file to download).
I will investigate threading library as Erel suggested then.
Thanks for help.
 
Upvote 0
Top