Android Question Pass variables to different activity modules

Ayabonga

Member
Hello Guys,

I have two activity modules named "Login" and "Main". In the login activity i have a diffrent layout for it where a user types username and password to login. After succesful login it then goes to "Main" activity and it also has a diffrent layout. In the Main module thats where most of the code run but now i want to save the info from the textboxes were the user types information save it into Php MyAdmin database according to the user logged in. Currently I can save the information but not according to the users who wrote the information, The User ID is aways 1.

My sql command to save is : sql.save = INSERT history (Remy, Henny, Soda) VALUES (?, ?, ?)
But now i cannot save these values according to the user because I cannot access Username and Password in the Main module to make it like: sql.save = INSERT history (Remy, Henny, Soda) VALUES (?, ?, ?) WHERE Username = ? AND Password = ?

I tried Using CallSubDelayed but i dont understand properly how to implement it and process globals.

Please check the attached code.

Login Activity Code:
Sub btnSignIn_Click
   
    If editUsername.Text = "" Or editPassword.Text = "" Then
        ToastMessageShow("username or password data is missing!",True)
        Log("username or password data is missing")
        Return
    End If
   
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("check_user", Array As String(editUsername.Text, editPassword.Text))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then ' Call to jRDC2 server was successful
        req.HandleJobAsync(j,"req")
        Wait For (req) req_Result(res As DBResult)
        If res.Rows.Size > 0 Then ' One or more records have been returned
         
            StartActivity(Main)
            ToastMessageShow("Login Successful",True)
            Log("User successful Login!")
        Else ' No records were returned
           
            ToastMessageShow("Please Register as new user",True)
            Log("Please Register as new user")
        End If
    Else ' Something went wrong with the call to the jRDC2 server
        Log("Something went wrong!!!!!!")
        Log("Error: " & j.ErrorMessage)
    End If
    j.Release

End Sub

Main Activity Code:
Sub btn_Execute_Click
    If connected Then

    Save
       
    End If
   
   
End Sub

Sub Save As ResumableSub
    Dim cmd As DBCommand = CreateCommand("save", Array As String(Remytxt.Text, Hennytxt.Text, Sodatxt.Text))
    Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log("Inserted successfully!")
        ToastMessageShow("Drink saved",True)

    Else
        Log("Error: " & j.ErrorMessage)
    End If
    j.Release
    Return j.Success
End Sub
 
Last edited:

Ayabonga

Member
Best solution is to switch to B4XPages and forget from all of these challenges.

You can use CallSubDelayed to start the next activity and pass variables: Using CallSubDelayed to interact between activities and services
Thank You for the response. I tried using CallSubDelayed, but I think I am still missing the concept/understandng. Can you please guide me on how I can implement them from the above information I shared. Converting to B4X Pages now might be tricky because I don't have much time, I need to submit my school project soon.

To be specific i need help to pass the variables from Login activity(Sub btnSignIn_Click) editbox : Username and Passaword to Main activity sub where I run the Save Sub. The Save Sub runs the SQL Command from B4J : sql.save = INSERT history (Remy, Henny, Soda) VALUES (?, ?, ?) WHERE Username = ? AND Password = ? . So I need Username and Password from the Login activiy to Main Activity.

Your help will be highly appreciated.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Converting to B4X Pages now might be tricky because I don't have much time, I need to submit my school project soon.
It is simpler than you think.

So I need Username and Password from the Login activiy to Main Activity.
I don't see the code that closes the login activity.

You should do something like:
B4X:
CallSubDelayed3(Main, "AfterLogin", UserName, Password)
 
  • Like
Reactions: eps
Upvote 0
Top