Concerning this post: https://www.b4x.com/android/forum/threads/implementing-a-callback-with-inline-java.168878/
When I run the following code, an error is issued: Constructor not found at line:
The code (in B4Xpages) is:
I tried to replace: Array(Me) using reflection library as:
But nothing happens: Wait For .. is not implemented
What is the correct code please. @Erel
When I run the following code, an error is issued: Constructor not found at line:
B4X:
callback.InitializeNewInstance(GetType(Me) & "$MyNetworkCallback", Array(Me)) '$ + class name. And pass Me to the constructor
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=%PROJECT_NAME%.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim callback As JavaObject
Dim r As Reflector
callback.InitializeNewInstance(GetType(Me) & "$MyNetworkCallback", Array(Me)) '$ + class name. And pass Me to the constructor
Wait For Network_State (Available As Boolean, Network As Object)
Log($"${Available}: ${Network}"$)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
End Sub
#if Java
public static class MyNetworkCallback extends android.net.ConnectivityManager.NetworkCallback {
private final BA ba;
public MyNetworkCallback(BA me) {
this.ba = me;
}
@Override
public void onAvailable(android.net.Network network) {
super.onAvailable(network);
ba.raiseEvent(this, "network_state", true, network);
}
@Override
public void onUnavailable() {
super.onUnavailable();
ba.raiseEvent(this, "network_state", false, null);
}
}
#End If
B4X:
Dim r as Reflector
callback.InitializeNewInstance(GetType(Me) & "$MyNetworkCallback", Array(r.GetActivityBA)) '$ + class name. And pass Me to the constructor
What is the correct code please. @Erel