Android Question Created simple test Library - trying to have Events appear in IDE - doesn't seem to work

stevew

Member
Licensed User
Longtime User
I create a simple class with an event to test creating a Library.

I can't seem to have events show up in IDE, and I get a 'missing RaiseSynchronousEvents' reported in Logs.

Can anyone explain this to me? I can get the results I want from the library, but I can't see the event in the IDE, and the 'missing RaiseSynchronousEvents' suggests somethign is not right!

Thanks!


***************************************************************
My class , compiled to a library, is as follows:

#Event: Click (val as Int)

Sub Class_Globals
Dim m_callback As Object
Dim m_CallingName As String
End Sub

'Initializes the object. Calling name is the Dim name of this object. ie Dim x as clsTestLibrary. 'x' is the calling name
'Class returns a calculated value by CallSub2(m_callback, m_CallingName & "_Click", val)
Public Sub Initialize(CallBack As Object, CallingName As String)
m_callback = CallBack
m_CallingName = CallingName
End Sub


Public Sub Init(val1 As Int, val2 As Int)

Dim val3 As Int
val3 = val1 * val2
SendReturnValue(val3)
End Sub

Sub SendReturnValue(val As Int)
If SubExists(m_callback, m_CallingName & "_Click") Then
CallSub2(m_callback, m_CallingName & "_Click", val)
End If
End Sub

**************************************************************
My Main activity used to create and test the Library is as follows:


#Region Project Attributes
#ApplicationLabel: Test Library
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#LibraryAuthor:
#LibraryName: TestLibrary2
#LibraryVersion: 1
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True

#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Private bt1 As Button
Private et1 As EditText
Private et2 As EditText
Private lbl1 As Label

Dim myLib As clsTestLibrary
Dim val1 As Int, val2 As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Activity.Title = Application.LabelName
myLib.Initialize(Me,"myLib")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub et2_TextChanged (Old As String, New As String)
val2 = New
End Sub

Sub et1_TextChanged (Old As String, New As String)
val1 = New
End Sub

Sub bt1_Click
myLib.Init(val1,val2)
End Sub

Sub myLib_Click(val As Int)
lbl1.Text = val
End Sub


When I run it I get the the label to display the anwer, but the log reports as follows:

*******************************************************************


** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@7a21209 time:930445
#3 mView = null
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@7a21209 time:931804
ViewPostImeInputStage processPointer 0
ViewPostImeInputStage processPointer 1
Unexpected event (missing RaiseSynchronousEvents): lib2_click
Check the unfiltered logs for the full stack trace.
java.lang.Throwable: stack dump
at java.lang.Thread.dumpStack(Thread.java:490)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:306)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1051)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:993)
at sw.TestLibrary2.clstestlibrary._sendreturnvalue(clstestlibrary.java:65)
at sw.TestLibrary2.clstestlibrary._init(clstestlibrary.java:46)
at sw.libtest2.main._btn1_click(main.java:414)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5714)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (main) Pause, UserClosed = false **
updateVisibility : ActivityRecord{503bf94 token=android.os.BinderProxy@7a21209 {sw.libtest2/sw.libtest2.main}} show : false
** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@7a21209 time:939968
ViewPostImeInputStage processKey 0
ViewPostImeInputStage processKey 1
** Activity (main) Pause, UserClosed = true **
#3 mView = null
-1 received
writer error
java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1988)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:357)
at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:160)
at java.lang.Thread.run(Thread.java:818)
Starting remote logger. Port: 10898

********************************************************************
I then created a new app and loaded the library . Main activity is as follows:

#Region Project Attributes
#ApplicationLabel: Library Test 2
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Private btn1 As Button
Private lbl1 As Label
Private lib2 As clsTestLibrary
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main2")
lib2.Initialize(Me,"lib2")
Activity.Title = Application.LabelName
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btn1_Click
lib2.Init(5,5)
End Sub

Sub lib2_Click(val As Int)
lbl1.Text = val
End Sub


********************************************************************
I cannot see the Lib2_Click envent in the IDE, but again get the calculated value in lbl1.


Log reports:


Unexpected event (missing RaiseSynchronousEvents): lib2_click
Check the unfiltered logs for the full stack trace.
java.lang.Throwable: stack dump
at java.lang.Thread.dumpStack(Thread.java:490)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:306)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1051)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:993)
at sw.TestLibrary2.clstestlibrary._sendreturnvalue(clstestlibrary.java:65)
at sw.TestLibrary2.clstestlibrary._init(clstestlibrary.java:46)
at sw.libtest2.main._btn1_click(main.java:414)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5714)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (main) Pause, UserClosed = false **
updateVisibility : ActivityRecord{503bf94 token=android.os.BinderProxy@7a21209 {sw.libtest2/sw.libtest2.main}} show : false
** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@7a21209 time:939968
ViewPostImeInputStage processKey 0
ViewPostImeInputStage processKey 1
** Activity (main) Pause, UserClosed = true **
#3 mView = null
-1 received
writer error
java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1988)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:357)
at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:160)
at java.lang.Thread.run(Thread.java:818)
Starting remote logger. Port: 10898
After accept
 

NJDude

Expert
Licensed User
Longtime User
A couple of things:

1- PLEASE use the [code]...[/code] tags.

Or better yet.

2- Export your code as ZIP and post it here, it will be easier to test.
 
Upvote 0

stevew

Member
Licensed User
Longtime User
Thank you for your replies. I'm new to using the forum, but will try again to try to explain, and also follow NJDude's suggestions.

I have been working on a project where I want to use Libraries complied from B4a. These libraries are to be designed so they can be reused in other projects. There are some things about libraries I'm not sure of - on how libraries get set up and work. I have written a simple test class to compile as a library for the following purpose:

I want the Library to expose one or more Events so that when they are used in an app the programer of the app can see what events there are and what they return.

The simple test class is meaningless and is only there to test the Event to see how to set up and use.

Below is the simple test class, with a 'Click' event. Below that is the main activity used to write and test the class. When writing and testing the 'Click' event is not exposed to 'main'. I tried looking for it both before compiling to the library and after compiling to the library, but could not see it. However, running main resulted in the value being returned and displayed in lbl1.Text.

I then created another project, and added the library to the project, The main activity for this is also below. Again, the 'Click' event is not exposed.

I also get in the Logs message 'Unexpected event (missing RaiseSynchronousEvents)' This is shown above in my first post.

I'm going to send this now. Then I will try to export the two projects as ZIP files in another post.

Thanks for your help (and patience).

Regards

Steve

B4X:
#Event: Click (val as Int)
'clsTextLibrary
Sub Class_Globals
   Dim m_callback As Object
   Dim m_CallingName As String
End Sub

'Initializes the object. Calling name is the Dim name of this object.  ie Dim x as clsTestLibrary.  'x' is the calling name
'Class returns a calculated value by CallSub2(m_callback, m_CallingName & "_Click", val)
Public Sub Initialize(CallBack As Object, CallingName As String)
   m_callback = CallBack
   m_CallingName = CallingName
End Sub


Public Sub Init(val1 As Int, val2 As Int)
   
   Dim val3 As Int
   val3 = val1 * val2
   SendReturnValue(val3)
End Sub

Sub SendReturnValue(val As Int)
   If SubExists(m_callback, m_CallingName & "_Click") Then
     CallSub2(m_callback, m_CallingName & "_Click", val)
   End If
End Sub

Below is the main activty I used to create teh Library. While creating and testing the 'Click' event is not exposed.

B4X:
#Region  Project Attributes
   #ApplicationLabel: Test Library
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
   #LibraryAuthor: 
   #LibraryName: TestLibrary2
   #LibraryVersion: 1
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
   
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Private bt1 As Button
   Private et1 As EditText
   Private et2 As EditText
   Private lbl1 As Label
   
   Dim myLib As clsTestLibrary
   Dim val1 As Int, val2 As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("main")
   Activity.Title = Application.LabelName
   myLib.Initialize(Me,"myLib")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub et2_TextChanged (Old As String, New As String)
   val2 = New
End Sub

Sub et1_TextChanged (Old As String, New As String)
   val1 = New
End Sub

Sub bt1_Click
   myLib.Init(val1,val2)
End Sub

Sub myLib_Click(val As Int)
   lbl1.Text = val
End Sub


Text project where Library is added. This runs and returns the value but again the Event is not exposed.

B4X:
#Region  Project Attributes
   #ApplicationLabel: Library Test 2
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Private btn1 As Button
   Private lbl1 As Label
   Private lib2 As clsTestLibrary
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("main2")
   lib2.Initialize(Me,"lib2")
   Activity.Title = Application.LabelName
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btn1_Click
   lib2.Init(5,5)
End Sub

Sub lib2_Click(val As Int)
   lbl1.Text = val
End Sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You should be using CallSubDelayed2 instead of Callsub2 as shown below:
B4X:
CallSub2(m_callback, m_CallingName & "_Click", val)

It should be:
B4X:
CallSubDelayed2(m_callback, m_CallingName & "_Click", val)

Read THIS
 
Upvote 0

stevew

Member
Licensed User
Longtime User
Attached are the two zip files.
 

Attachments

  • testlibrary.zip
    8.7 KB · Views: 156
  • libtest2.zip
    7.9 KB · Views: 169
Upvote 0

stevew

Member
Licensed User
Longtime User
NJDude. I have tried both CallSub2 and CallSubDelayed2. They both work at returning the value from the Library. However, after loading the library in a new project, I call see all the Subs, but I cannot see the Event - no matter which CallSub I use.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What you try to do will not work.
Events are raised by the OS, you cannot generate events in the class.
If you handle an event raised internaly in the class you can call a routine in the calling module.
In your case, with your example, if you want to return the product of two values you could define a routine for this, like:
B4X:
'Calculates the product of val1 and val2
Public Sub Product(val1 As Double, val2 As Double) As Double
    Return val1 * val2
End Sub

and the calling routine:
upload_2017-10-11_17-17-58.png


The comment before the Product routine is displayed in the in-line help.

In your project you get an answer when you call myLib.Init(val1,val2), but this will not generate any event.
So, without knowing what exactly you expect it's difficult to give a concrete answer.

Do you want to develop a CustomView or a standard Class?

You might have a look at the B4x CustomViews Booklet, link in my signature.
There you find detailed explanations with examples.
 
Upvote 0

LucianDesign

Member
Licensed User
Longtime User
NJDude. I have tried both CallSub2 and CallSubDelayed2. They both work at returning the value from the Library. However, after loading the library in a new project, I call see all the Subs, but I cannot see the Event - no matter which CallSub I use.
If you are referring to the autocomplete function from the IDE, then these events are not listed there.
B4X:
#Event
is used for CustomViews in the Abstract designer.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
If you are referring to the autocomplete function from the IDE, then these events are not listed there.
B4X:
#Event
is used for CustomViews in the Abstract designer.
They are only listed when/after the class is compiled into lib and used as such
 
Upvote 0
Top