In my activity, there is a scenario where the user can click the back button before the activity is loaded. This back button click needs to be handled.
What I basically do is:
When I run the code, I get the Java Crash below. Presumably, because the elements of the activity are only half loaded:
Error occurred on line: 2374 (WB)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.B4XViewWrapper.asLabelWrapper(B4XViewWrapper.java:191)
at anywheresoftware.b4a.objects.B4XViewWrapper.getTextColor(B4XViewWrapper.java:219)
at b4a.example.WB$ResumableSub_ExecuteBackRule.resume(WB.java:1595)
at b4a.example.WB._executebackrule(WB.java:1528)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.WB$HandleKeyDelayed.runDirectly(WB.java:232)
at b4a.example.WB$HandleKeyDelayed.run(WB.java:229)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
** Activity (WB) Pause, UserClosed = true **
Any suggestions on how to prevent this crash? Or how to better handle the exit so that the crash does not occur.
What I basically do is:
B4X:
// Back Button Handling Code
// Detect Premature Exit
If prematureExit = true then
Activity.Finish
end if
When I run the code, I get the Java Crash below. Presumably, because the elements of the activity are only half loaded:
Error occurred on line: 2374 (WB)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.B4XViewWrapper.asLabelWrapper(B4XViewWrapper.java:191)
at anywheresoftware.b4a.objects.B4XViewWrapper.getTextColor(B4XViewWrapper.java:219)
at b4a.example.WB$ResumableSub_ExecuteBackRule.resume(WB.java:1595)
at b4a.example.WB._executebackrule(WB.java:1528)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.WB$HandleKeyDelayed.runDirectly(WB.java:232)
at b4a.example.WB$HandleKeyDelayed.run(WB.java:229)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
** Activity (WB) Pause, UserClosed = true **
Any suggestions on how to prevent this crash? Or how to better handle the exit so that the crash does not occur.