Hi all,
I’m fairly new to B4A and Android development, and I’m stuck on an issue that I can’t quite reason through yet. I’ve searched the forum but haven’t found a case that matches this exactly.
Dim job As HttpJob
job.Initialize("login", Me)
job.PostString(ServerUrl & "/login", $"username=${txtUser.Text}&password=${txtPass.Text}"$)
End Sub
JobDone fires correctly after the freeze, but on first run only.
I’m fairly new to B4A and Android development, and I’m stuck on an issue that I can’t quite reason through yet. I’ve searched the forum but haven’t found a case that matches this exactly.
The problem
On a fresh install of my app, the very first HTTP request causes the app to freeze for a few seconds, and sometimes it triggers an ANR. If I force-close the app and open it again, everything works perfectly after that.Environment
- B4A version: 13.x
- Android target: SDK 34
- Device tested: Pixel 6 (Android 14) and emulator
- Libraries: OkHttpUtils2, JSON, Core
What the app does
- App starts → shows a login screen
- On login button click, I make a POST request to my server
- Server responds quickly (confirmed via logs)
Relevant code (simplified)
Sub btnLogin_ClickDim job As HttpJob
job.Initialize("login", Me)
job.PostString(ServerUrl & "/login", $"username=${txtUser.Text}&password=${txtPass.Text}"$)
End Sub
JobDone fires correctly after the freeze, but on first run only.
What I’ve tried
- Moving the request to Starter service
- Adding a short Sleep(0) before the request
- Checking permissions (INTERNET is present)
- Disabling cleartext traffic issues (using HTTPS anyway)
Questions
- Is there something about first-run initialization (OkHttp, TLS, DNS?) that I should be handling differently?
- Do I need to warm up OkHttp or run the first request in a service instead of an activity?
- Is there a common B4A pattern to avoid ANR on the very first network call?