Android Question CallSub in B4x

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
Hi,

I have in a B4xPage class a button with CallSub2 Method

B4X:
Private Sub btn_continue_Click
    StopCamera
    Log(Variablen.GeleseneText)
    '
    CallSub2(GeneralSettings,"QRcodeTextLesen",Variablen.GeleseneText)
    B4XPages.ClosePage(Me)
    StartActivity(GeneralSettings)
End Sub

the page will closed and Page Generalsettings will open but CallSub in Generalsettings has no reaction.

B4X:
Sub QRcodeTextLesen(msg as String)
    Log("Aufgerufen")
    Dim Trenner() As String
    Trenner = Regex.Split("\|",msg )
    txtVorname.text = Trenner(0)
    txtNachname.Text = Trenner(1)
    txtemail.Text = Trenner(2)
    txtPW_Login.Text = Trenner(3)
   
End Sub

I get no error code and no warning
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Why are you using "StartActivity" in a b4xpages app?

This is what I normally do to pass data to a B4xpage class

B4X:
    Private b4xp As B4xpageClass = B4XPages.GetPage("B4xPageClass")  'Already initialised the class elsewhere with b4xpages.AddPage
    B4XPages.ShowPage("B4xPageClass")
    b4xp.QRcodeTextLesen(data)
    B4XPages.ClosePage(Me)
 
Upvote 1

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
I have started with this app 3 years ago and include StartActivity and so on.
Now, I can not change to B4X version, because the App has lot of codes an pages.
I have try it, to change but I get lot of Errors and then I have see, I need lot of time for this.

Now, I have implement the example from
and now I need, how can I pass data from B4XClass to activity pages.
And how cann use CallSub ??

Your Method not works at me

I hoppe you can understand me :)
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
It looks like you are trying to use both methods in the same app.

The problem is probably that the activity has not yet started and so the CallSub is lost.

Try using CallSubDelayed as per this example, it seems that it will start the activity.

 
Upvote 0

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
Then I get this following error

Error occurred on line: 0 (GeneralSettings)
java.lang.Exception: Sub qrcodetextlesen signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject yamutec.app.generalsettings_subs_0._qrcodetextlesen() throws java.lang.Exception

class java.lang.String,

Pointed in the Activity (GeneralSettings) top firstline
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Are you calling

Callsubdelayed2(GeneralSetting,"QRcodeTextLesen",data)

as you are passing 1 parameter?

You can check if the sub exists by calling

xui.subexists(GeneralSettings,"QRcodeTextLesen",1) befordhand
 
Upvote 0

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
this is my code in B4XMainPage Class

B4X:
Private Sub btn_continue_Click
    
    StopCamera
    Log(Variablen.GeleseneText)
    
    
    xui.subexists(GeneralSettings,"QRcodeTextLesen",1)
    
    StartActivity("GeneralSettings")
    
    CallSubDelayed2(GeneralSettings,"QRcodeTextLesen",Variablen.GeleseneText)
    'B4XPages.ClosePage(Me)
    
End Sub

Sub in Generalsettings Activity
B4X:
Sub QRcodeTextLesen(msg As String)
    
    Dim Trenner() As String
    
    Trenner = Regex.Split("\|",msg)
    txtVorname.text = Trenner(0)
    txtNachname.Text = Trenner(1)
    txtemail.Text = Trenner(2)
    txtPW_Login.Text = Trenner(3)
    
End Sub


Get Error:
Error occurred on line: 0 (GeneralSettings)
java.lang.Exception: Sub qrcodetextlesen signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject yamutec.app.generalsettings_subs_0._qrcodetextlesen() throws java.lang.Exception

class java.lang.String,
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
xui.subexists(GeneralSettings,"QRcodeTextLesen",1) returns a boolean so the correct code should be:

B4X:
StartActivity("GeneralSettings")

if  xui.subexists(GeneralSettings,"QRcodeTextLesen",1) then
    CallSubDelayed2(GeneralSettings,"QRcodeTextLesen",Variablen.GeleseneText)
else
    Log("QRcodeTextLesen does not exist on General Settings")
end if
 
Upvote 0

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
it is same behavior

Get:
Error occurred on line: 0 (GeneralSettings)
java.lang.Exception: Sub qrcodetextlesen signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject yamutec.app.generalsettings_subs_0._qrcodetextlesen() throws java.lang.Exception

class java.lang.String,
 
Upvote 0

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
I have try it, but not works :)
No error log

I don't know what is the issue.
 

Attachments

  • Barcode_Reader_edit.zip
    14.4 KB · Views: 195
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
This works as expected on my device. No b4xpages just activities. Press the button on main and the messagebox from activity2 appears.

Your example upload seems to be missing GeneralSettings

Main Activity
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #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.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    CallSubDelayed2(Activity2,"callme","Test string")
End Sub

Activity 2
B4X:
#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.
    Private xui As XUI
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.

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("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub callme(param As String)
    xui.MsgboxAsync(param,"Test")
End Sub
 

Attachments

  • testactivitycall.zip
    9.7 KB · Views: 183
Upvote 0

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
Hi Andrew,

your sample is only activity. For pass parameter beetwen two aktivities is not problem.
The question was, pass parameter from B4Xpages to activity
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Is it possible, do this without B4X
I mean by use only Activity and StartActivity?
You did say you only wanted Activity.
But,
Here is a Pages to Activity Example.

It is much the same.
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=pagestoactviity.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")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    CallSubDelayed2(Activity2,"callme","This is from b4xpages")
End Sub


B4X:
#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.
    Private xui As XUI
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.

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("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

public Sub callme(param As String)
    xui.MsgboxAsync(param,"Test")
End Sub
 

Attachments

  • pagestoactviity.zip
    14.6 KB · Views: 177
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
What device do you have?

I have tried on a Redmi Note 8 Pro - Android 11
Samsung Galaxy Tab A - Android 7.11
Google Pixel 2 XL - Android 11
Honor 7 - Android 6.0

These are the phone I have charged on my desk and it works on all of these.

Not sure what could be going wrong.
 
Upvote 0
Top