Bug? Sleep not resumed (context is paused): anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub

ArminKh1993

Active Member
Hi, It seems it's an issue in b4a v10.7
Sleep not resumed also on Activity_Resume
For example:
B4X:
Dim lbl As Label
    lbl.initialize("")
    Activity.AddView(lbl,100dip,100dip,100dip,100dip)
    lbl.Text = "Label 1"

Sleep(5000)

Dim lbl2 As Label
    lbl2.initialize("")
    Activity.AddView(lbl2,100dip,300dip,100dip,100dip)
    lbl2.Text = "Label 2"

Look at the code above, Imagine phone screen is locked. Then run app with compile it by b4a and then unlock phone screen.
as you can see just Label 1 will be created and nothing will happen about Label 2 Also if Activity_Resume occured.
In other words, if the code reaches line 6(Sleep) while the phone screen is locked then this message will printed in log windows:Sleep not resumed (context is paused) and neither the code(Sleep) itself nor its subsequent lines are executed after the Activity_Resume.
Also activity_pause will break the code and subsequent lines will not executed after Activity_Resume.

This is new in b4a 10.7(exist in too old version of b4a too) because i'm working on a project for more than 8 months. and i see this problem in my splash screen when i upgrade b4a to v10.7. It's okay in b4a v10.6.

i think code should be resumed after "Sleep" if Activity_Resume occured.Some thing like CallSubDelayed
thanks
 
Last edited:

ArminKh1993

Active Member
To Reproduce follow this steps:
1- Install And Run App
2- When lbl is counting press home button(to Pause Activity)
then you can see this message will printed in log windows:Sleep not resumed (context is paused)
and then when you comeback and Activity_Resume raised then nothing happen and you can see counting is paused and not resumed,
subsequent lines are not executed after the Activity_Resume.

Note: I Guess this is an issue in classes
because if you put this code directly in activity(not to use class) then there is not any problem and counting will continue after Activity_Resume raised
thank u @Erel
 

Attachments

  • Sleep.zip
    417.4 KB · Views: 245

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use File - Export as zip to create the zip.

This is the expected behavior and it hasn't changed in B4A 10.7. The context was paused so the sleep wasn't resumed. You need to take care of this yourself (example: https://www.b4x.com/android/forum/t...ingindicator-loading-indicator.92243/#content).

Correct solution is to switch to B4XPages and forget from all such issues.
 

ArminKh1993

Active Member
Correct solution is to switch to B4XPages and forget from all such issues.

At the moment, because it is a very heavy project, I can not switch and that App is not a cross-platform

I downloaded it but I did not understand how you managed it,Do you mean the code you wrote in Activity_Resume?

Just a question: Why Sleep can resume in activity but can not resumed in classes?
My class is using same context so when activity is paused Sleep command can wait for resume in any classes which same context
Is there a particular problem with automatically managing this? Or am I doing something wrong?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
,Do you mean the code you wrote in Activity_Resume?
Yes.

Why Sleep can resume in activity but can not resumed in classes?
It is related to events being queued in activities. There is no similar queue in classes.
I can not switch and that App is not a cross-platform
It doesn't matter whether the app is cross platform or not. In the long run it will be worth the efforts to switch to B4XPages. It will make many things much simpler.
 

ArminKh1993

Active Member
Ok thank u will have a try to switch
But I think it is better not to allow (or maybe a warning)Sleep to be used in the classes when everything breaks down when the context is paused.
 

ArminKh1993

Active Member
Like this I think. It restarts so if you want to carry on from where it left off you would need to save and restore that state.
Yes, it's ok but some time we can't reset and show everything from starting point.
I know there is many solution to fix it but this makes me use Sleep with fear and uncertainty
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…