Android Question How can i use variables between activities

Sreenadh OG

Member
Licensed User
Hi,
I have two activity, first activity contain EditText and Button, I want to pass query to next activity
to load webview..
my example code is given below..
B4X:
Sub Btn_Click
Dim StrQry as string
If txtFrom.Text<>"" Then
    StrQry="Select * from tbl_Case where date='"& txtFrom.Text&"'"
End If
StartActivity(SearchCase) 'In this activity i want to use StrQry
'How can i use this variable in this activity
End sub

Next activity (SearchCase) contain...
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
WebViewSearchCase.LoadHtml(WebviewDesign.ExecuteAddressHtml(Calculation.Sqlcnn,Calculation.SearchCaseQuery, Null, 0, True))
End Sub
 

buras3

Active Member
Licensed User
B4X:
'activity1
Sub Process_Globals
   Dim TxtFromStr as string
End Sub
Sub Btn_Click
TxtFromStr =txtFrom.Text
end sub

'activity2
Sub Activity_Create(FirstTime AsBoolean)
dim GetTxtFrom as string
GetTxtFrom =activity1.TxtFromStr
end sub
 

Sreenadh OG

Member
Licensed User
Thank you, But how can i pass array variables...Example is given below.
B4X:
For No=0 To Range-1
        If StrName(No)<>""  Then
            CallSubDelayed3(AddAddressBook,"ShowList",StrName(No),Ph(No))  
        End if
    Next
 

Sreenadh OG

Member
Licensed User
But how can i access these variable in next activity ?
First Activity..
B4X:
CallSubDelayed2(AddAddressBook,"LoopVal",Range)
CallSubDelayed3(AddAddressBook,"ShowList",StrName,Ph)
Second Activity..
B4X:
Sub LoopVal(Range As Int )
     RangeLoop =Range
End Sub
Sub ShowList(Name As String,Phone As String)'Error code
Try
    Dim no As Int
    For no=0 To RangeLoop-1
        txtName.Text=Name(no)
        txtPhone.Text=Phone(no)
    Next
Catch
    ToastMessageShow("Select any of searching option" ,True)
End Try
End Sub
 
Top