[บทเรียน,B4A] แอพไม่ตอบสนอง (Application not responding)

Theera

Well-Known Member
Licensed User
Longtime User

เพิ่มโค้ดต่อไปนี้เข้าไป

B4X:
    Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        DisableStrictMode
    End If
    End Sub
   
    Private Sub DisableStrictMode
    'This was recommended to make the FCM work.  Fix the error.  Called from if first time.
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build.VERSION")
    If jo.GetField("SDK_INT") > 9 Then
        Dim policy As JavaObject
        policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
        policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
        Dim sm As JavaObject
        sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
    End If
End Sub
 
Top