Android Question B4A: Impossible behavior

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,
I start an app with a pushservice. When the message is clicked, a download starts. Everything runs fine, until ... see my comments.

B4X:
Sub schreib
   If writing=True Then Return
   writing=True
   Label1.Text=Basis.t_saving & "x"
   ' The 3 lines above are executed. I can see label1.text

   Msgbox ("vor deletepic","")
' not executed. I see no msgbox
   Label1.Text="1"
' not executed
...

When I am in debug mode, the app is alive and I start the push notice, everything runs fine. But when the app is not allive and has to be started via the push notice, I cannot debug.

Strange ...
 

aidymp

Well-Known Member
Licensed User
Longtime User
Hi,
I start an app with a pushservice. When the message is clicked, a download starts. Everything runs fine, until ... see my comments.

B4X:
Sub schreib
   If writing=True Then Return
   writing=True
   Label1.Text=Basis.t_saving & "x"
   ' The 3 lines above are executed. I can see label1.text

   Msgbox ("vor deletepic","")
' not executed. I see no msgbox
   Label1.Text="1"
' not executed
...

When I am in debug mode, the app is alive and I start the push notice, everything runs fine. But when the app is not allive and has to be started via the push notice, I cannot debug.

Strange ...


Maybe like me you are doing too much in the main thread to allow the screen update! I used to get this a lot, the tip I was given was to put things like this in separate subs and call them with callsubdelayed

So

B4X:
Sub schreib
   If writing=True Then Return
   writing=True
   Label1.Text=Basis.t_saving & "x"
   ' The 3 lines above are executed. I can see label1.text
CallSubDelayed(Me, "UpdateDisplay")
...

Sub UpdateDisplay

   Msgbox ("vor deletepic","")
' not executed. I see no msgbox
   Label1.Text="1"
' not executed
  End Sub

That was all it took to get my apps working!
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
I need these messageboxes (or other means of showing something on the screen) to monitor the progress, I think some lines are not executed.

Now I removed all the lines showing something on the display, same result.

Does anybody have an idea how to sacv e the log in release mode or to monitor the progress without writing much code?
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you!

This code works like a charm in debug mode. But in release mode, started with a push service, it does not work, pls see comments:

B4X:
Sub schreib
    If writing=True Then Return
    writing=True
    Label1.Text="Saving"
' I see this


    CallSubDelayed (Me,updatescreen(1))
' I do not see the "1", It remains "Saving" for about a minute, then the main screen appears. The code should save a picture, the picture is not there.
   
    Basis.deletepic (Main.photonumber)
    ' Msgbox ("vor readphoto","")
    ' Label1.Text="2"
    CallSubDelayed (Me,updatescreen(2))
    Basis.readphoto (Main.photonumber & ".dat")
    Dim s As String
    s=Main.hostname & "_downloaded.php?nr=" & Main.photonumber & "&p=" & Settings.pnr
    DoEvents
    Dim jobx As HttpJob
    jobx.Initialize ("x",Me)
    Log (s)
    ' Msgbox (s,"")
    ' Label1.Text=s
    jobx.Download (s)
    CallSubDelayed (Me,updatescreen(3))
End Sub


Sub updatescreen (s As String)
    ' ToastMessageShow (s,True)
    Label1.Text=s
    DoEvents

I need help here, I am willing to pay for this :(
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
CallSubDelayed (Me,updatescreen(1))
are you sure you can give a parameter with callsubdelayed?

Try
B4X:
CallSubDelayed2(Me,"updatescreen","1")
and additional use this sub

B4X:
Sub updatescreen (s As Object)
    If s Is String Then
      Dim t As String = s
      ' ToastMessageShow (s,True)
    Log("updatescreen ("&t&")")
        Label1.Text=t
    'DoEvents
    End If
End Sub
 
Last edited:
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
It does not crash in debug mode. Why?

It very much sounds like you are doing too much in the main thread, I have been using B4A for just over a year, and I fall for the same mistakes. Android is not a good OS for beginners (especially, if you don't understand how it works, like me initially) MSGBOX is certain situations is a bad command, and should be avoided if possible, writing large data to sdcards inside the main module will block the main thread, and will cause an ANR. running in debug mode, apps work slightly different. I know this for a fact, as I too was stuck! inside the tools folder of the android SDK is a bat file called monitor.bat. if you run this, and are connected via USB (usb debugging enabled) this will provide a very substantial log even in release mode!

I hope this helps a little.

Thanks

Aidy
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
MSGBOX is certain situations is a bad command, and should be avoided if possible
Who said that? If you need one, use one.
If you want to call MsgBox safely from a different thread, you have to put the call in a separate sub and call this sub with CallSubDelayed. That's all.

if you run this, and are connected via USB (usb debugging enabled) this will provide a very substantial log even in release mode!
It displays the same information that you get by unchecking Filter in the Logs tab of your IDE (for the log part). But it is more convenient to use, for sure.
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
Who said that? If you need one, use one.
If you want to call MsgBox safely from a different thread, you have to put the call in a separate sub and call this sub with CallSubDelayed. That's all.
It displays the same information that you get by unchecking Filter in the Logs tab of your IDE (for the log part). But it is more convenient to use, for sure.

Yes, I meant it should be called with CallSubDelayed (I just didnt say it!)

It displays the same information that you get by unchecking Filter in the Logs tab of your IDE (for the log part). But it is more convenient to use, for sure.

Using different versions of Android on an emulator. un/checking the filter, I get either no information or a bare minimum depending on the Android version im emulating. this was a major problem to me, until someone smart mentioned the monitor.bat (actually that was you! ;))

Thanks

Aidy
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Using different versions of Android on an emulator. un/checking the filter, I get either no information or a bare minimum depending on the Android version im emulating. this was a major problem to me, until someone smart mentioned the monitor.bat (actually that was you! ;))
Ah, for emulators! Yes you're right. There's a difference indeed.
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you both! I set the path for java_exe correctly, java.exe and javaw.exe exist and I get this:

upload_2015-11-9_16-48-0.png


Should I add the path to my environment variable path?
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
"It displays the same information that you get by unchecking Filter in the Logs tab of your IDE (for the log part). But it is more convenient to use, for sure."

Unchecking filter won't help me when I have the problems in releease mode. Or am I missing something important?
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
> You can read the logs in release mode if you are connected in USB debug mode.

Forgive my stupidity, but how do I do that? USB debug mode is on, the phone is connected via cable, but I see nothing.

> I don't understand your code. Is this an Activity module? Or Service?

Activity module.

> Why are you calling DoEvents?

Should I not? I am using DonManfreds MaterialCircleProgress. I thought it would rin smoother with a DoEvents now and then. In Delphi a similar function sppeds up screen updates.

> Why are you using CallSubDelayed here?

Suggestion by Aidymp, see above
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Sorry, now I have seen the logs. But only the first time I compiled the program, not at the second. I continue trying.
 
Upvote 0
Top