can someone tell me why the Activity_Resume is run 2 times?
What can I do to make the Activity_Resume run only once?
Or is it normal? If so, then I have not noticed until now.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
Msgbox2Async("Message", "Titel", "OK", "", "", Null, False)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_Resume
Sleep(1000)
' Msgbox("Message", "Titel")
Msgbox2Async("Message", "Titel", "OK", "", "", Null, False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
Log("Result=" & Result)
End If
End Sub
Log from Smasung A5(2017) with Android 8.0 and B4a 8.0:
I don't see this behavior with your code on Nexus 5X running Android 8.1.
It is not the expected behavior. However a correctly structured program should expect the activity to be paused and resumed many times. For example the user can click on the recent apps button when the dialog appears.
So your program should properly handle such cases.
In principle, that did not matter, but in my case, I show the Amdob Consense and privacy policy at the first app launch, and it does not look good if it's displayed twice within a second.
As a countermeasure you could define a global variable and use it as a semaphore. On first call to Consense policy request set it accordingly so that on an eventual second call your code won't display the policy again.
As a countermeasure you could define a global variable and use it as a semaphore. On first call to Consense policy request set it accordingly so that on an eventual second call your code won't display the policy again.
It was just a way to avoid displaying the consent message multiple times. As Erel already stated it is normal that Main.Resume will be called multiple times, so if you display your message in it having a semaphore IMHO is a good idea.
Alternatively you could move the message to Main.Create under the FirstTime = True condition
Already tried, it does not work.
There is almost nothing left that I have not already tried.
The bug is just in Android 8.0!
With all other versions there are no problems.
Can someone, with a Samsung with Android 8.0, please run the test from the first post and post the log output.
I would like to know if only my device has the error or is a mistake of Samsung.
Thank you!
I am currently trying with another launcher and will try to disable/enable accessibility tools or screen readers. Will provide feedback if I can find something about