Android Question Creating a SQL query using input from multiple activities?

Discussion in 'Android Questions' started by gareththomasnz, Jul 29, 2015.

  1. gareththomasnz

    gareththomasnz Member Licensed User

    I am making a CRUD app for a client

    He has asked that I have input fields across multiple screens

    The user inputs to a couple of fields - hits the next button and proceeds to the next screen

    In all there are 7 input screens and a save to database button on the last screen

    I have put each screen into its own activity so the user can use the back button of the device

    The add (to database) is a sub on the first activity - I can use callsub on the last activity to call this

    But I am thinking if each screen (activity) has some input of the fields how do I get the add sub in the first activity to get the field data from those other activities?

    Sub AddEntry

    Dim Query As String

    Query = 
    "INSERT INTO User VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
    Array As String(rdbMr.Checked , rdbMrs.Checked, rdbMiss.Checked, rdbElecInsp.Checked, rdbSparky.Checked, _
            rdbTech.Checked, rdbOther.Checked, txtFirstName.Text, txtMidName.Text, txtLastName.Text, txtPersEmail.Text, _
            txtPerPh.Text, txtPerCell.Text, txtPerWork.Text, txtStreet.Text, txtCity.Text, txtSuburb.Text, txtRego.Text, txtEmpComp.Text, _
            txtCompAddress.Text, txtEmpTown.Text, txtContact.Text,txtCompPhone.Text, txtCompEmail.Text, rdbNN.Checked, rdbCR.Checked, txtSiteSf.Text))
    ToastMessageShow("Entry added"False)    ' confirmation for the user

    End Sub
    I am just looking in the following for an answer:
    Last edited: Jul 29, 2015
  2. Mahares

    Mahares Well Known Member Licensed User

    One way I would do it is:
    1. Declare Process-Global variables in the main activity: exple: Dim Street as String
    2. If txtStreet.Text is input in the 3rd activity, you can have : Main.Street =txtStreet.Text
    3. Finally, when you are ready to save the SQLite record in the main activity, you use this in the query: Main.Street instead of txtStreet.Text
    gareththomasnz likes this.
  3. gareththomasnz

    gareththomasnz Member Licensed User

    One question:

    Main.Street =txtStreet.Text

    Goes into the first activity or third?
  4. Mahares

    Mahares Well Known Member Licensed User

    It goes in the 3rd activity
    gareththomasnz likes this.
  5. gareththomasnz

    gareththomasnz Member Licensed User

    OK thanks for your help

    yes and in Main it just needs Street not Main.Street
    Last edited: Jul 30, 2015
  6. DonManfred

    DonManfred Expert Licensed User

    gareththomasnz likes this.
  7. gareththomasnz

    gareththomasnz Member Licensed User

    The save button is in activity eight & the actual sql sub is in activity one

    I just tried CallSubDelayed and lucky for me that works as the screen goes back to activity 1 upon saveing

    OK so I know that works - the next problem for me is checking if the data is actually added correctly to the database

    It is creating the entry in the database - BUT - only the data from the first activity is going into the database

    All the other fields from the other activities are not passing through - is this because the activities are paused?

    I am using the code as suggested in the post above.

    Should the following:

    Main.Street =txtStreet.Text

    Go into Sub Process Globals, Sub Globals or Sub Activity_Create?

    I stuck it into Sub Activity_Create which creates no error but wont load up the DB

    So I will experiment...
    Last edited: Aug 4, 2015
  8. klaus

    klaus Expert Licensed User

    You should move Main.Street = txtStreet.Text to Activity_Pause in txtStreets' Activity.
    That way whenever the Activity is paused Main.Street is updated.
    gareththomasnz likes this.
  9. gareththomasnz

    gareththomasnz Member Licensed User

    OK fingers crossed I was just going to try that but backed out LOL - I have it adding the row to the database - just most of the cells didn't load data yet

    Hopefully this will work


    It needs simply to load the data into the database & go back to screen one after pressing
    the save button - and show the toast message

    So it is all there just not writing to the DB

    Help much appreciated if you can explain what is wrong
    Last edited: Aug 5, 2015
  10. gareththomasnz

    gareththomasnz Member Licensed User

    Admin Password is "applepie"

    PS it only created the new row with the Main.Street = txtStreet.text in the sub oncreate in the other modules

    this version has it in the on pause & it doesn't even load the new row
    Last edited: Aug 4, 2015
  11. eurojam

    eurojam Well-Known Member Licensed User

    Hey Gareth,
    I think, theonly problem is in your PanelNine Activity in the Sub Activity_Create when you check your Input as admin.
    here you are deleting the database edited before and copy the original database from assets, so the input data will be deleted!
    'Put this to comment and it will work!

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    If FirstTime Then
    File.Delete(File.DirInternal, "electapp.db"' <- this produces the error described above...
    'check if the database already exists
            If File.Exists(File.DirInternal, "electapp.db") = False Then
    'copy the default DB
                File.Copy(File.DirAssets, "electapp.db"File.DirInternal, "electapp.db")
    'if not, initialize it
                Main.SQL1.Initialize(File.DirInternal, "electapp.db"True)
    'and create it
                'copy the default DB
                File.Copy(File.DirAssets, "electapp.db"File.DirInternal, "electapp.db")
    'if yes, initialize it
                Main.SQL1.Initialize(File.DirInternal, "electapp.db"True)
    End If
    End If   
    End Sub
    gareththomasnz and DonManfred like this.
  12. gareththomasnz

    gareththomasnz Member Licensed User

    Thanks for the reply

    Yes I believe with that commented out it did load the new row of data but that row only passed the data from the first panel all the rest was empty

    So this is not the only fault (although it clearly is a fault).

    Also Erel says Klaus is correct & that it should indeed be in Activity_Pause. It may be that I uncommented the panel nine block while testing that?


    Yes thank heavens it is working now.

    It was a combination of the code on panel nine that needed to be commented or removed and the other code that needed to be placed into Activity_Pause.

    Last edited: Aug 5, 2015
  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