Android Question Error with B4A Socket

davideb

Member
Licensed User
Longtime User
I've tried the old socket example.
All goes correctly with debug, but when i go to the release mode, the app break and give me this exception.

(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException

Timer Tick:
Sub Timer1_Tick
    Dim BC As ByteConverter
    
    If InputStream1.BytesAvailable > 0 Then
        Timer1.Enabled = False
        
        Dim buffer(8192) As Byte
'        'raf.Initialize3(buffer, True)
    Try
         InputStream1.ReadBytes(buffer, 0, buffer.Length)
    Catch
        Log(LastException)
    End Try
      
'        Dim s As String=BC.StringFromBytes(buffer,"UTF-8")
'        lblArt1.Text=s
        'Timer1.Enabled = True
    End If
End Sub

Manifest File:
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'AddPermission("android.permission.ACCESS_COARSE_LOCATION")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_WIFI_STATE")
AddPermission("android.permission.ACCESS_NETWORK_STATE")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
AddPermission("android.permission.INTERNET")
'AddPermission("android.permission.ACCESS_COARSE_UPDATES")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")
CreateResourceFromFile(Macro, Themes.LightTheme)

How can i solve it
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

davideb

Member
Licensed User
Longtime User
USE the forumsearch! ;-)


and

I've searched a lot. Anyway it runs perfectly, now
 
Upvote 0
Top