Android Question Activity_WindowFocusChanged Error

hanyelmehy

Active Member
Licensed User
Longtime User
when use Activity_WindowFocusChanged with SDK 34 i get these error
B4X:
showexam_activity_windowfocuschanged (java line: 609)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA students.one.onlineexam.showexam.activityBA' on a null object reference in method 'java.lang.String students.one.onlineexam.showexam._activity_windowfocuschanged(boolean)'
    at students.one.onlineexam.showexam._activity_windowfocuschanged(showexam.java:609)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at students.one.onlineexam.showexam.onWindowFocusChanged(showexam.java:191)
    at androidx.appcompat.view.WindowCallbackWrapper.onWindowFocusChanged(WindowCallbackWrapper.java:125)
    at com.android.internal.policy.DecorView.onWindowFocusChanged(DecorView.java:1789)
    at android.view.View.dispatchWindowFocusChanged(View.java:15277)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1508)
    at android.view.ViewRootImpl.handleWindowFocusChanged(ViewRootImpl.java:3690)
    at android.view.ViewRootImpl.-$$Nest$mhandleWindowFocusChanged(Unknown Source:0)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl(ViewRootImpl.java:5538)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:5452)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7898)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
 

hanyelmehy

Active Member
Licensed User
Longtime User
Upload a small project showing the issue.

I dont think anyone can help without knowing what you have done and how.
i simply use
B4X:
Sub Activity_WindowFocusChanged (Focused As Boolean)
    Log(Focused)
End Sub
crash happend after change sdk from 33 to 34
when remove above code no crash happens
 
Upvote 0

Spavlyuk

Active Member
Licensed User
I'm guessing you're not using B4XPages. Generally that event is weird since the activity can be "paused" when it's raised, meaning you can't really do anything.
You can try the code B4XPages is using, maybe it will help. Otherwise I'd suggest avoiding that event.

B4X:
Dim module As JavaObject
module.InitializeStatic(jo.RunMethodJO("getActivityBA", Null).GetField("className")).SetField("dontPause", True)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…