Android Question B4xPages App crash in debug when Main contain IME

Gianni Sassanelli

Active Member
Licensed User
Longtime User
Hi
i have strange behavior in b4xPages app if I add IME to the Main module.

Strangely, the application starts and work very good when I compile it in release mode
But doesn't start if I run it in debug mode.
The error it gives me is:

java.lang.RuntimeException: Unable to create service it.techservice.tpick_r2.starter: java.lang.RuntimeException: java.net.SocketException: Connection reset
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4264)
at android.app.ActivityThread.access$1600(ActivityThread.java:246)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1974)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7876)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: java.lang.RuntimeException: java.net.SocketException: Connection reset
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:164)
at anywheresoftware.b4a.shell.Shell.start(Shell.java:102)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:105)
at it.techservice.tpick_r2.starter.onCreate(starter.java:34)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4252)
... 8 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:215)
at java.net.SocketInputStream.read(SocketInputStream.java:144)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:248)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:288)
at java.io.BufferedInputStream.read(BufferedInputStream.java:347)
at java.io.DataInputStream.readFully(DataInputStream.java:198)
at java.io.DataInputStream.readInt(DataInputStream.java:389)
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:136)
... 12 more
 

MarcoRome

Expert
Licensed User
Longtime User
The IME object is declared/initialized in a "non-visual" location (e.g., Starter or Main.Process_Globals) or too early, without a valid Activity in debug, the VM crashes, the debugger channel closes, and you see the "Connection reset" message.

In release, however, it starts because there is no debug channel and the timing changes.

Do not use Dim IME As IME in Starter or Main.Process_Globals.
Declare and initialize the IME only in the Page(s) where you need it, when the host Activity is already live (in B4XPage_Created).
 
Upvote 0

Gianni Sassanelli

Active Member
Licensed User
Longtime User
OK, I declare ime in the main because I manage the HeightChanged event.
I need this to handle some resizing when the keyboard is activated.

then i handle the show ok keyboard for all pages

B4X:
Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
    Dim jo As JavaObject
    Dim vw As View
    jo.InitializeContext
    Dim window As JavaObject = jo.RunMethodJO("getWindow", Null)
    vw=window.RunMethod("getCurrentFocus",Null)            ' Get Edittext that has Focus
    Dim objs() As Object
    Dim mp As Map
    mp.Initialize
    mp.Put("OldHeight",OldHeight)
    mp.Put("NewHeight",NewHeight)
    mp.Put("Edt",vw)
    Dim needAdjust As Boolean
    needAdjust     = (NewHeight < OldHeight)
    objs             = Array (needAdjust, mp)
    B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "IME_HeightChanged",objs)
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/threads/handle-the-soft-keyboard-with-the-ime-library.14832/

1756131984109.png
 
Upvote 0
Top