Java Question Newbie Creating Library With Events

blackansible

New Member
Licensed User
Longtime User
I am trying to create a library with events but i dont get to raise the event. I can not imagine what i am doing wrong.

The java code is the following one.

package anywheresoftware.b4a.sample;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Events;

@ShortName("FirstLib")
@Events(values={"OnMultiplyElapsed (result As Int)"})
public class FirstLib {

private String _eventName;

public void Initialize(String eventName) {
this._eventName = eventName;
}

/**
* Multiplies x 2
* @param x
* @return
*/
public int multiply(BA ba, int x) {

int result;
result = x * 2;
ba.raiseEvent(this, _eventName + "_OnMultiplyElapsed", new Object[]{result});
return x * 2;
}
}



And the b4Android code is the following one.

Sub Activity_Create(FirstTime As Boolean)
f.Initialize("FirstLibIMP")
Log(f.multiply (5))
End Sub

Sub FirstLibIMP_OnMultiplyElapsed (result As Int)

End Sub


The event is never launched !!!!!
 

warwound

Expert
Licensed User
Longtime User
Also ensure that your _eventName property is properly lower cased:

B4X:
public void Initialize(String eventName) {
  this._eventName = eventName.toLowerCase(BA.cul);
}

BA.cul means to convert the String to lower case based on the device's current locale, not essential but i see it's always used in the official B4A libraries so i use it in my own libraries too.
I guess it makes the code more compatible with various foreign languages.

Martin.
 

blackansible

New Member
Licensed User
Longtime User
Problem still persist.

I have made the changes that you recommended but the event is not launched.

This is copy of the log

>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON
--- registering native functions ---
Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=b4a.example/.main }
Start proc b4a.example for activity b4a.example/.main: pid=310 uid=10047 gids={3003, 3002, 1015}
Shutting down VM
adbd disconnected
NOTE: attach of thread 'Binder Thread #3' failed
generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x375ee0:0x375fec] in 417662 ns
generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x3c43c0:0x3c447c] in 358315 ns
Displayed activity b4a.example/.main: 1857 ms (total 1857 ms)
** Activity (main) Create, isFirst = true **
ignoring event: firstlibimp__onmultiplyelapsed
10
** Activity (main) Resume **
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44f7c5f0
 

blackansible

New Member
Licensed User
Longtime User
Thank you Erel. All is working !!!!

This is amazing IDE. I can make application so quick without learning Android. Thanks for the quick support. The community is going to make this program to be a MUST for developing apps.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…