Android Question (RESOLVE) sending message to waiting queue of uninitialized activity (submitjob)

fishwolf

Well-Known Member
Licensed User
Longtime User
I have a simple form with a input text field

when/where i can check the value of field for start with other functions.

if i check in create function i have this warning and app is blocked

warning log:
sending message to waiting queue of uninitialized activity (submitjob)
 

fishwolf

Well-Known Member
Licensed User
Longtime User
yes, if field value is empty i use httpjob

profile:
Sub Activity_Create(FirstTime As Boolean)
   
    Activity.LoadLayout("Profile")
        
    If EditEmail.Text.Length == 0 Then
    
        'call get profile
        
    End if
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
I have reproduced the problem

Activity1 is the procedure of start
Activity2 is the procedure with use the service

The error and warning on log i have OLNY when installed app first time for both Activity

for test "Select account and confirm"

Thanks
 

Attachments

  • HttpProblem.zip
    13.8 KB · Views: 157
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
Try to add

B4X:
StartReceiver(HttpUtils2Service)

without success, same problem

Try to start procedure after a delay of 3 seconds, same problem

i have discovery that if remove the account selection work fine

B4X:
Dim jo As JavaObject
   
        jo.InitializeStatic("android.accounts.AccountManager")
        GetAccounts_StartActivityForResult(jo.RunMethod("newChooseAccountIntent", Array(Null, Null, Array As String("com.google"), Null, Null, Null, Null)))
        Wait For ion_Event (MethodName As String, Args() As Object)
        If -1 = Args(0) Then 'resultCode = RESULT_OK
            Dim i As Intent = Args(1)
            Log("Account=" & i.GetExtra("authAccount"))
            EditEmail.text = i.GetExtra("authAccount")
        End If

Suggestion?
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
First step is to switch to B4XPages. It will make things much simpler and will hopefully solve this issue.
I have a app with 20 Activity and 1000 accounts that must recovery. I have already try to see b4xpages, it isn't more simplex.
Exist a workaround ?
Other versione of httpjobs?
I don't understand because only the first time exist this problem.
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Try not using Wait For in Activity_Create. It really messes with Android App Life Cycle.

B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim GetJson As HttpJob

    
    Activity.LoadLayout("Layout1")
    
    If EditEmail.Text.Length = 0 Then
        
        Dim jo As JavaObject
    
        jo.InitializeStatic("android.accounts.AccountManager")
        GetAccounts_StartActivityForResult(jo.RunMethod("newChooseAccountIntent", Array(Null, Null, Array As String("com.google"), Null, Null, Null, Null)))

        
    End If    
    
End Sub

Sub ion_Event (MethodName As String, Args() As Object)
        If -1 = Args(0) Then 'resultCode = RESULT_OK
            Dim i As Intent = Args(1)
            Log("Account=" & i.GetExtra("authAccount"))
            EditEmail.text = i.GetExtra("authAccount")
        End If
        
        GetJson.Initialize("GetProfile", Me)
        GetJson.Download("https://dummyjson.com/products/1")
End Sub
Note: Underneath the hood, a Wait For will execute a return. If Wait For is used in Activity_Create, a return will be executed at that time and Android will continue the app life cycle, eventually calling Activity_Resume, even though all the code in Activty_Create has not been executed. Also, the pop-up created by GetAccounts_xxx will pause your App (Activity_Pause is called) and once done, will resume your app (Activity_Resume called again). And the Wait For will re-enter (not re-execute) a finished Activity_Create (from Android's life cycle perspective).

Technically, if you can query what Google account the user is using (see link below), you would not need to use the ActivityForResult/IonEvent method. You just would do the following steps in Activity_Resume:

1) Check if user is signed into an account, if not, fire up the intent (via plain StartActivity) to have the user pick the account.

Done.

When you start the activity and Activity_Resume is called, have the user pick the account (via the intent)). The app is paused (Activity_Paused) and once a user picked an account your app is resumed. (Activity_Resume). Therefore, without picking an account/having signed into an account, the user would never get passed the initial few lines in Activity_Resume that implement the above step. And no ActivityForResult/IonEvent needed.

Link:
How to query account information: https://stackoverflow.com/a/4039018
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Activity_Resume pseudo-code:
B4X:
Sub Activity_Resume
   If EditEmail.Text.Length = 0 Then
       'Check if user is already logged in via stackoverflow post
       'If yes, assign email to EditEmail.Text
       'If no, fire up intent
   End If
   If EditMail.Text.Length <> 0 Then
      ' Process regular code
   End If
End
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I added the following code to my little test program
B4X:
            StartReceiver(HttpUtils2Service)
           
            Do While HttpUtils2Service.TempFolder = ""
                Log("Waiting HttpUtils2Service")
                Sleep(100)
            Loop

NOTE: I would NOT normally put a log message in a loop like above, but just wanted to see what was going on.

It took 532 times before connection was done.

That's like 53 seconds on a COLD boot for the connection to be made.

My users don't want to wait that long. Gotta be a better way


ONE NOTE: I did notice that my main B4XPages program started right up after this test program was run. So it seems (not 100% sure) that once a connection is made it is good for all apps?

B4X:
[ATTACH type="full"]145029[/ATTACH]
 

Attachments

  • 1692725089085.png
    1692725089085.png
    52.1 KB · Views: 137
  • Test.zip
    16.9 KB · Views: 131
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If you want to, ignore the posts above (I still think they are a good way to process what you are trying to do, especially with how Android/B4A's app life cycle work) since I've been able to reproduce a similar issue in this thread:
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
To verify, I've created Activity3 and moved the code handling to Activity_Resume w/ion_event as a separate sub and I'm experiencing the same issue: on the initial install of the application, the service does not start for about 15 seconds. Once run, the next execution the app seems to just work fine, and to reproduce it from then on, I have to uninstall the app and re-install it. The crazy part is that @Robert Valentino's test app (thread linked in the reply before this one) only seems to act up after the phone is restarted (and there it takes almost a minute to fire up the receiver). Something interesting is happening here...
** Activity (activity3) Create (first time) **
** Activity (activity3) Resume **
** Activity (activity3) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Account=ollie3a@gmail.com
** Activity (activity3) Resume **
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
Waiting HttpUtils2Service
*** Receiver (httputils2service) Receive (first time) ***
JobName = GetProfile, Success = true
{"id":1,"title":"iPhone 9","description":"An apple mobile which is nothing like apple","price":549,"discountPercentage":12.96,"rating":4.69,"stock":94,"brand":"Apple","category":"smartphones","thumbnail":"https://i.dummyjson.com/data/products/1/thumbnail.jpg","images":["https://i.dummyjson.com/data/products/1/1.jpg","https://i.dummyjson.com/data/products/1/2.jpg","https://i.dummyjson.com/data/products/1/3.jpg","https://i.dummyjson.com/data/products/1/4.jpg","https://i.dummyjson.com/data/products/1/thumbnail.jpg"]}
title=iPhone 9
 

Attachments

  • HttpProblem.v2.zip
    20.4 KB · Views: 138
Upvote 0
Top