Android Question Best Practices - closing an app?

tseyfarth

Member
Licensed User
Longtime User
Hello,

What are the best practices when closing an app from within an app?

Thank you,
Tim
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Sub CloseActivities
   Dim jo As JavaObject
   jo.InitializeContext
   jo.RunMethod("finishAffinity", Null)
End Sub

Or
B4X:
Dim jo As JavaObject 
jo.InitializeContext 
jo.RunMethod("finishAndRemoveTask", Null)
 
Last edited:
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
Thank you Star-Dust,

However I get an error during runtime -

Any idea how to fix this?

Tim

*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
Error occurred on line: 228 (B4XMainPage)
java.lang.NoSuchFieldException: sharedProcessBA
at java.base/java.lang.Class.getDeclaredField(Class.java:2412)
at anywheresoftware.b4j.object.JavaObject.InitializeContext(JavaObject.java:57)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$1.run(BA.java:236)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
This method only works on Android. You can't use it with B4J
 
Upvote 0
Top