Problem with PHP-MySQL-Get

Catom

Member
Licensed User
Longtime User
Hi,

I'm having problems getting data from my server, I've following two different approaches posted here but both of them crashes at the same line.

First:
I'm developing for Android 2.3 in mind
I'm testing in a real device (USB) with Android 4.04

The error is "android.os.NetworkOnMainThreadException"
The problematic line is -> Receive = Response.GetString("UTF8")

The code:

B4X:
Sub Process_Globals
   Dim host As HttpClient
   Dim Request As HttpRequest
   
   Dim hostAddress As String
   Dim Transmit As String
   Dim Receive As String
   
   Dim task_Lugares As Int = 1   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
        hostAddress =    "http://myhost.com/dataGet.php"
      Transmit =       hostAddress & ""
      host.Initialize("host")
    End If
   Request.InitializeGet(Transmit)
   Request.Timeout = 60000
   host.Execute(Request, task_Lugares)

   ProgressDialogShow("Loading...")
End Sub
Sub host_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   ProgressDialogHide

   Receive = Response.GetString("UTF8") ' <--- CRAAAASSHHH!!!

    Log("Response from server: " & Receive)
End Sub

I'm guessing if the returned JSON is so big ... It's 76193 chars long...

Thanks for any help
 

NJDude

Expert
Licensed User
Longtime User
Make sure you have a line like the one below on your manifest:
B4X:
<uses-sdk android:minSdkVersion="4"/>

If you have something like this will not work:
B4X:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
 
Upvote 0

Catom

Member
Licensed User
Longtime User
Thanks, I thought I was doing something wrong because the examples I saw worked perfectly on my phone...

Thanks again!

**** SOLVED ****
 
Upvote 0
Top