Android Question Intercept Event from external lib

Francesco Maresca

Member
Licensed User
Longtime User
Hi,
I need to intercept event from external lib.


In Android Studio i have this code:
B4X:
public class ScanDevicesActivity extends AppCompatActivity implements ModuleIface {

public void onItemClick(View v, int position) {
   ModuleIface.init(this,ModuleIface.this) 
}

@Overridepublic 
void onStatusChange(int statusCode) 
{
  
}

}

When Call the ModuleIface.init the library call automatically onStatusChange, how can I intercept this event?

The object of the init are:
- Context
- ModuleIface

My try in B4A:

B4X:
  #AdditionalJar: mylibrary
   
  Sub Test()
     Dim R2 as Reflector
     Dim Jo As JavaObject
     Jo.InitializeNewInstance("mylibrary.KeyModule",Null)
     Dim CallBack As Object = Jo.CreateEvent("onStatusChange", "Callback", Null)     
     jo.RunMethod("init",Array(r2.GetActivity, e))     

 
 End Sub
  
 Sub Callback_Event (MethodName As String, Args() As Object) As Object
      Log("onStatusChange")
  End If
 

Francesco Maresca

Member
Licensed User
Longtime User
I have another problem:

This is my new code

B4X:
  sub Test()
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim Jo As JavaObject
    Jo.InitializeNewInstance("mylibrary.KeyModule",Null)
    Dim CallBack As Object = Jo.CreateEventFromUI ("full.package.name.ModuleIface", "Callback", Null)
    Jo.RunMethod("init",Array(ctxt, CallBack))
   end sub
   
   
 Sub Callback_Event (MethodName As String, Args() As Object) 
    Log(MethodName)
    Log("onStatusChange")
  End Sub


The MethodName is Always "ToString". How can I intercept the correct method name?
 
Upvote 0

Francesco Maresca

Member
Licensed User
Longtime User
I think the problem is in the extension of the class.

In "Android Studio" I find
B4X:
public class extends ScanDevicesActivity AppCompatActivity implements ModuleIface {

How can I translate this line in B4A?
 
Upvote 0
Top