Android Question Get result of an Intent in Activity_Resume

I've seen a lot of questions like that about getting the result of an Intent, but many of them get confused in how to use it.

I would like to know if I can get the result of an Intent through Activity_Resume, the application that is called only returns a string and with the name 'RESULT_INTENT'.

Below the flame code and what I thought of doing to get this answer, however without success.

B4X:
Sub Activity_Resume
    'forces all nfc intents to be sent to this activity
    If prevIntent.IsInitialized Then
        'prevIntent.PutExtra()
        prevIntent = Activity.GetStartingIntent
        ToastMessageShow("extra name : " & prevIntent.GetExtra("RESULT_INTENT"), True)
    End If
End Sub

Sub ButtonNFC_Click
    prevIntent.Initialize(prevIntent.ACTION_VIEW,"http://www.nfcgedi.com")
    StartActivity(prevIntent)
End Sub
 
1. Use Log.
2. I don't understand your code. Is another app starting your app with an intent?

I must start another application, until then everything is fine, but then I must wait and get the answer that he will send me to show it on screen to the user.
 
Upvote 0
1. Search for StartActivityForResult

2. Start with:
B4X:
Sub Activity_Resume
    Log(Activity.GetStartingIntent)
End Sub

This is the complete code I have to call another apk, and wait for the result it sends me.

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#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
    Private prevIntent As Intent
    
    Private ion As Object
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 ButtonNFC As Button
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("nfc")
End Sub

Sub Activity_Resume
    'forces all nfc intents to be sent to this activity
    If prevIntent.IsInitialized Then
        'prevIntent.PutExtra()
        prevIntent = Activity.GetStartingIntent
        ToastMessageShow("extra name : " & Activity.GetStartingIntent, True)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Sub ion_Event(MethodName As String, Args() As Object) As Object
    'Args(0) = resultCode
    'Args(1) = intent
    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
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub

Sub ButtonNFC_Click
    prevIntent.Initialize(prevIntent.ACTION_VIEW,"http://www.nfcgedi.com")
    'StartActivity(prevIntent)
    StartActivityForResult(prevIntent)
End Sub



When I do this, Log (Activity.GetStartingIntent), it returns me:

intent (intent) {
flg = ...
cmp: = ...
}

Is there any way I can get only the return value ?!
 
Upvote 0
When you call StartActivityForResult => you get the result in ion_Event.

Activity.GetStartingIntent serves a different purpose: https://www.b4x.com/android/forum/threads/receiving-shared-images-from-other-apps.81041/#content


So, the result must come within ion_Event.?! IT'S OK.

But, what exactly is this 'resultCode' and 'intent' that are commented on ?!

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

I know it must be something simple like prevIntent.GetData or prevIntent.ExtrasToString. Sorry I'm really confused on how to get this result with these methods in B4A.

B4X:
Sub ion_Event(MethodName As String, Args() As Object) As Object
    Args(0) = prevIntent.ExtrasToString
    Args(1) = prevIntent.GetData
    Return Null
End Sub
 
Upvote 0
Top