Android Question Threading after jobdone

Discussion in 'Android Questions' started by Derek Jee, Aug 21, 2015.

  1. Derek Jee

    Derek Jee Active Member Licensed User

    Hi there..

    I need to process the response to a http request in a separate thread. I will receive some json and parse it, then add it to a table in my database. This all needs to be done using a single thread. I have tried using the threading lib but it does not run the sub and process the data. Can anyone supply a little bit of code to help me out?

    Thanks..

    Derek
     
  2. stevel05

    stevel05 Expert Licensed User

    You won't be able to update the Table (or anything else in the Gui) from within a thread, you'll need to delegate that to a sub on the main thread using the Threads RunOnGuiThread method.
     
  3. Derek Jee

    Derek Jee Active Member Licensed User

    Hi Steve

    Thanks for the reply. So to clarify, I cannot process my response from a http request in a new thread? Processing data from the downloaded files well halt the UI.. Isn't that what the threading lib is enabling me to do or am I missing the point?

    Kindest regards

    Derek
     
  4. stevel05

    stevel05 Expert Licensed User

    Yes, you can process the responses, just not update the Gui with the results. You will have to call a sub outside of the thread to do that.

    See the attached example.

    Note: you cannot debug an application that uses a thread, this will only run in Release mode.
     

    Attached Files:

  5. Erel

    Erel Administrator Staff Member Licensed User

    Why do you need to use a background thread?

    How large is the json file? Are you correctly inserting the data to the table (in a single transaction)?
     
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