Android Question FIXED - sending message to waiting queue of uninitialized activity (submitjob) - with test program

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have been getting this message (like others)

NOW - I have attached a test.zip that contains a program that just causes this to happen.

AND it is very repeatable

This is how I can recreate it every time.

1) Have the IDE loaded and program open
2) HARD reboot the device you are going to run this program on
3) After device reboots - select Clear Project in IDE
4) Compile and Run (I am using Release or Release Obfuscated)

The program will hang on trying to do the download - EVERY Time.

IF I hit the task button and select Close All and then click on the icon to run the program it runs just find.

I know this is a crappie program and it wasn't made to do anything but cause this program to hang so that maybe as a group we can figure out what is causing it.

Below is logs when fails

B4X:
Logger connected to: R9ANB0B3XMJ
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
#SupportedOrientations attribute must be set to landscape or portrait.
B4XMainPage::Initialize
B4XMainPage::B4XPage_Created
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
DownloadJob Initialize
DownloadJob Requesting Download
** Activity (main) Resume **
B4XMainPage::B4XPage_Appear
sending message to waiting queue of uninitialized activity (submitjob)
*** Receiver (httputils2service) Receive (first time) ***

Below are logs when runs fine
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
#SupportedOrientations attribute must be set to landscape or portrait.
B4XMainPage::Initialize
B4XMainPage::B4XPage_Created
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
DownloadJob Initialize
DownloadJob Requesting Download
** Activity (main) Resume **
B4XMainPage::B4XPage_Appear
*** Receiver (httputils2service) Receive (first time) ***
Job Success:true
Job Release
** Activity (main) Pause event (activity is not paused). **
B4XMainPage::B4XPage_Disappear
** Service (starter) Destroy (ignored)**


My test device is a Samsung Galaxy Tab A7 - SM-T500 one UI v4.1 Android Version 12
 
Last edited:

agraham

Expert
Licensed User
Longtime User
It looks to me that starting the download in Activity_Create is a bad idea. This is my best guess as to what is going. OkHttpUtils2 usesCallSubDelayed to post a call to a Sub called SubmitJob but from a cold start this does not succeed as the Activity has at that point not been fully created because you haven't yet returned from Activity_Create and run Activity_Resume and the Android system code associated with both those events. I think Android caches Activities so when you try again it already has an Activity instance available and so runs fine - or something like that. It is obviously a timing/sequence problem as it runs fine afterwards.

Try moving the download to Activity_Resume, or better still, as it is a B4XPages app, put it in B4XPage_Created and see what happens then.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
from second post below op's:
erel.png
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK to all.

I updated the app to do a callsubdelayed to call the download and still had a problem
So I added a 1 second delay within the download program and now seems to work all the time.

My app use to be a regular app that moved to b4xpages and this call has been there for some time.

Will see how to move it out
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have tried calling HttpJob in B4XPage_Created, B4XPage_Appear.
I have tried adding a timer delay (also using CallSubDelayed when calling)

ON A COLD BOOT [restarting device] only HttpJob Hangs

Please help. I need to check for an internet connection on startup.

But ever time on a cold boot HttpJob hangs. There has to be a fix for this problem????

Attached find my small program
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I just realize there was no
B4X:
AddPermission(android.permission.INTERNET)
in the manifest but even after adding it on a cold boot the problem is still there.

Going to look at using shell and ping to test for internet.

But not sure if that will help. Because after testing for internet I need to download a file so it will probably hang.

Well thanks for confirming the problem. I know I can sometimes be a moron, but this is driving me nuts (my users as well. A lot of them it seems use tablets and turn them off week to week only using them for my App and they keep reporting this hang)

BobVal
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I don't think its anything to do with 'testing for Internet'. The problem is that HttpJob can't actually post the job demand to to the Activity message queue using CallSubDelayed as the Activity doesn't at that tIme seem to be initialized. Its an Android/B4A timing/architectural problem and nothing to do with whether the Internet is available or not.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK, so how and when can I / should I call Check_4Internet that would work all the time?

In my real App the routine is located in standard class module
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Ok, so as a work around here what I did.

I set a timer for 5 seconds before calling my Http functions

if the timer expires before I receive an response I call a routine in main that does
and Activity.Finish, StartActivity(me)

Just restart the app and then the calls work as they should.

STRANGE way to handle this problem, but at least my users won't hang anymore


Strike this. Doesn't always work. Back to drawing board
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
I have exactly the same problem, my application checks authorization at startup (in B4XMainPage -> B4XPage_Created)
 
Upvote 0

locasms

Member
Licensed User
Longtime User
I have this problem too, when it occurs I have to close and open the app until it returns to normal, usually with android boot, it solves it.
 
Upvote 0

jahswant

Well-Known Member
Licensed User
Longtime User
I exposed the same issue here.
After a cold boot or reboot. I have to wait a minute before launching my app for web requests to work. Just wait a minute and everything will work perfectly.
 
Upvote 0

jahswant

Well-Known Member
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I've modded the test to see if it has anything to do with an active internet connection. In my case, it does not. The connection (at least according to Android) is ok, but the HttpUtils2Service receiver does not start until about a minute later.

Pixel 7 / Android 13 / B4A 12.5
 

Attachments

  • Test.v2.zip
    20.7 KB · Views: 151
Upvote 0
Top