Android Question [Solved] B4XPages and StartActivityForResult

asales

Expert
Licensed User
Longtime User
I tried to use this code in a B4XPage:
but I get this error:
B4X:
b4xmainpage_getba (java line: 95)
java.lang.ClassNotFoundException: llections=null, b4xpages=null, button1=(Button): Left=385, Top=482, Width=321, Height=321, Tag=, Text=
, dateutils=null, ion=java.lang.Object@aae6d19, main=null
, page2=[b4xcollections=null, b4xpages=null, dateutils=null
, main=null, page2=[b4xcollections=null, b4xpages=null, dateutils=null
, main=null, page2=null, root=null
, starter=null, wobblemenu1=null, xui=null
], root=(BALayout) anywheresoftware.b4a.BALayout{1e00bf7 V.E...... ......ID 0,0-0,0 #16}
Here is the code of the B4XMainPage:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Public Page2 As B4XPage2
    Private WobbleMenu1 As WobbleMenu
    Private Button1 As Button
    
    Public ion As Object
End Sub

'You can add more parameters here.
Public Sub Initialize
    B4XPages.GetManager.TransitionAnimationDuration = 0
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("lay_main")
    Page2.Initialize
    B4XPages.AddPageAndCreate("Page2", Page2)   
End Sub

Sub B4XPage_Appear
    Log("sono qui")
    WobbleMenu1.SetCurrentTab(1)
End Sub

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

Sub WobbleMenu1_Tab2Click
    B4XPages.ShowPage("Page2")
End Sub

Sub Button1_Click
    ShowPicker
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
    'Args(0) = resultCode
    'Args(1) = intent
    Return Null
End Sub

Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub

Sub ShowPicker
    Dim i As Intent
    i.Initialize("android.intent.action.RINGTONE_PICKER", "")
    i.PutExtra("android.intent.extra.ringtone.TYPE", 1)
    StartActivityForResult(i)
End Sub

Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Is possible to use StartActivityForResult in a B4XPage? If yes, how?
Thanks in advance for any tips.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The only change needed is in GetBA code:
B4X:
Sub ShowPicker
    Dim i As Intent
    i.Initialize("android.intent.action.RINGTONE_PICKER", "")
    i.PutExtra("android.intent.extra.ringtone.TYPE", 1)
    StartActivityForResult(i)
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
    If -1 = Args(0) Then 'resultCode = RESULT_OK
        Dim i As Intent = Args(1)
        Dim jo As JavaObject = i
        Dim uri As String = jo.RunMethod("getParcelableExtra", _
       Array As Object("android.intent.extra.ringtone.PICKED_URI"))
        Log(uri)
    End If
    Return Null
End Sub

Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject = Me
    Return jo.RunMethod("getBA", Null)
End Sub
And add : Private ion As Object in Class_Globals.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…