B4J Question [SOLVED] Restart program (here B4J)

GMan

Well-Known Member
Licensed User
Longtime User
Is it possible to auto-restart an B4J-programm ?
 

Cableguy

Expert
Licensed User
Longtime User
I would say so, create a batch file on the app-finished event and call it...
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
Done - works fine :)

Depending on jShell and @Erel 's sample i used this in both parts, here the "Re-Starter"

B4X:
Sub Process_Globals

End Sub

Sub AppStart (Args() As String)
    Dim shl As Shell
    Try
        shl.Initialize("shl", "java.exe" , Array As String("-jar", "Your.jar"))
        shl.WorkingDirectory = File.DirApp
        shl.Run(-1)
    Catch
        Log(LastException.Message)
    End Try
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success Then
        Log(StdOut)
    End If
End Sub


'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
For all:
here the part from the Program that should be restartet.

Put the code in any event you like, i.e. Sub ExitButton_Click:
B4X:
Sub ExitButton_Click
   
    Dim sf As Object = xui.Msgbox2Async("Proggi wird neu gestartet !","Neustart","OK","","Abbruch", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim shl As Shell
        Try
            shl.Initialize("shl", "java.exe" , Array As String("-jar", "YourRestart.jar"))
            shl.WorkingDirectory = File.DirApp
            shl.Run(-1)
        Catch
            Log(LastException.Message)
        End Try
        Log("Neustart!!!")
           
        ExitApplication
    End If
End Sub
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
You can create another program that starts the first program after 1-2 seconds. Start the second program with jShell and call ExitApplication.

hello erel it is possible to have two executables (2 programs in the same project). I am trying for the client to have a program and when it detects an update, download and initialize again similar to Visual Studio's ClickOnce. I've searched the forum a lot and this is the most similar thing I find
 
Upvote 0
Top