Android Question How to refer to Activity in B4A 's library

Theera

Expert
Licensed User
Longtime User
Refer to this I've tried to use AI answer for me, but it doesn't help me clearly.
B4X:
Public Sub CheckForReceivedFiles As LoadResult
    Dim Activity As Activity = B4XPages.GetNativeParent(B4XPages.MainPage)
    If IsRelevantIntent(Activity.GetStartingIntent) Then
        Dim in As Intent = Activity.GetStartingIntent
        Dim uri As String
        If in.HasExtra("android.intent.extra.STREAM") Then
            uri = in.As(JavaObject).RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
        Else
            uri = in.GetData
        End If
        Dim res As LoadResult = CreateLoadResult(True, "ContentDir", uri)
        ExtractInformationFromURI(res.FileName, res)
        Return res
    End If
    Return CreateLoadResult(False, "", "")
End Sub

If I need to convert for B4A (Non-B4XPages) ,How to code?
 
Last edited:

Theera

Expert
Licensed User
Longtime User
Looks like you only need to delete line #2.
My problem is that Activity is in the class module (it is in the same module of Activity)

Filehandler.bas is developer for B4XPages, but If it is used for only B4A, it doesn't work.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. The sooner you switch to B4XPages, the sooner many things will become simpler.

2. If I understood correctly, you need to get a reference to the Activity from inside a class instance. You can pass the Activity object in the Initialize sub of the class:
B4X:
Public Class_Globals
 Private mParent As Activity
End Sub

Public Sub Initialize (Parent As Activity)
 mParent = Parent
 
Upvote 0
Top