Android Question How can i use variables between activities

Discussion in 'Android Questions' started by Sreenadh OG, Jan 17, 2015.

  1. Sreenadh OG

    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..
    Code:
    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...
    Code:
    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, 
    Null0True))
    End Sub
     
  2. buras3

    buras3 Active Member Licensed User

    Code:
    '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 likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. Sreenadh OG

    Sreenadh OG Member Licensed User

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

    Erel Administrator Staff Member Licensed User

    Exactly like you pass any other variable.
    It will be more efficient to pass the whole array with a single call:
    Code:
    CallSubDelayed3(AddAddressBook,"ShowList",StrName,Ph)
     
    Sreenadh OG and DonManfred like this.
  6. Sreenadh OG

    Sreenadh OG Member Licensed User

    But how can i access these variable in next activity ?
    First Activity..
    Code:
    CallSubDelayed2(AddAddressBook,"LoopVal",Range)
    CallSubDelayed3(AddAddressBook,
    "ShowList",StrName,Ph)
    Second Activity..
    Code:
    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
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    If you are passing an array then the other sub should expect an array:
    Code:
    Sub LoopVal (Range() As Int)
     
    Log(Range(0))
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice