Android Question HTTPUtils PostSting only works in Activity_Create

Derek Jee

Active Member
Licensed User
Longtime User
Hello there

I want to be able to update my internal database on the main activity screen but only when the user clicks a button to do this.. If I put the HttpUtils.PostString in the Activity_Create sub then all works well as per the example posted, but If I move the line to my Button Click sub it does not run JobDone sub.. I know I am missing something and would love someone to tell me what..

Thank you,


Derek.

Sub Activity_Create(FirstTime AsBoolean)
If FirstTime Then

HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
EndIf
HttpUtils.PostString("Job1", ServerUrl, "SELECT * FROM MobInspections")
 

Derek Jee

Active Member
Licensed User
Longtime User
I think you better post more code than what you just did.
Oops.. Sorry, the sample post was here http://www.b4x.com/android/forum/threads/connect-android-to-ms-sql-server-tutorial.13166/#content
I want to Send the HTTP poststring in my CreatNewDatabase sub instead of the Create_Activity sub but it does not like it. No error..

Thank you


Sub CreateNewDatabase
SQL1.Initialize(File.DirRootExternal, "1.db", True, "3ur0l1nk", "")
SQL1. etc..
HttpUtils.PostString("Job1", ServerUrl, "SELECT * FROM MobInspections")
SQL1.ExecNonQuery("INSERT INTO Inspections VALUES('abc8', 8, 2)")
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT col1, col2, col3 FROM Inspections")
Do Database Stuff
Cursor1.Close
End Sub
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
it runs async so you have to do that in the http job completion sub.

you also need to parse the data that's sent back to the app.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Thanks sorex

I now understand that it runs async but I would like to start it when the user is ready to instead of running on activity create. Is there no other way or did I miss something you said about the job completion sub. I have a JobDone sub which sorts the JSON just like the example. I guess the way to go would be to open a new activity just for the database load on my click event and then move on to the next one once it has processed?

Thank you.. Sorry but my knowledge is only 5 days old :)

Derek
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Hi Sorex

I am now using the HttpUtils2 framework which allows me to send multiple posts. I will do all of my posts on a separate activity to keep them separate from the main forms.. Thank you for your guidance

Kind regards,

Derek.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you can call it whenever you want.

at start, when a sub ends or when a user clicks a button.

you should decide/design how the flow goes.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Thank you.. It didn't seem to want to run in the click sub using HttpUtils, but using HttpUtils2 it works a treat from my click sub..

Thank you again..

Derek
 
Upvote 0
Top