Android Question Activity_Resume run 2 times

D

Deleted member 103

Guest
Hi,

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

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 
D

Deleted member 103

Guest
Filippo, try (sorry :p) also writing Sleep(1000) before
Msgbox2Async("Message", "Titel", "OK", "", "", Null, False)
in the "original" project
B4X:
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:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Result=-1
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
 
Upvote 0
D

Deleted member 103

Guest
Hello Erel,

I think you did not understand the problem.
This is just the example in my first post, it is not about any wrong structured programs.

I don't see this behavior with your code on Nexus 5X running Android 8.1.
It may be that works well with Android 8.1, but the fact is that with Android 8.0 does not work, and I can not catch the error.
 
Upvote 0
D

Deleted member 103

Guest
I understood. What I meant to say is that your program should work properly even if the activity is paused and resumed multiple times.
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.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
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.
 
Upvote 0
D

Deleted member 103

Guest
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.
I have already tried that, does not look so good.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
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
 
Upvote 0
D

Deleted member 103

Guest
Hi @udg ,

all these possibilities are known to me, I just wanted to show that in Android 8.0 the APP launch is not normal or different.

If now Erel thinks this can not do anything, then it's OK and I have to look for another way.
 
  • Like
Reactions: udg
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Could be enough to use FirstTime as process global variable? I mean, using copy of it.
B4X:
Process_Globals

Dim mFirstTime As Boolean

B4X:
Activity_Create...
mFirstTime = FirstTime

B4X:
Activity_Resume
    If mFirstTime Then
 
Upvote 0
D

Deleted member 103

Guest
Could be enough to use FirstTime as process global variable? I mean, using copy of it.
B4X:
Process_Globals

Dim mFirstTime As Boolean

B4X:
Activity_Create...
mFirstTime = FirstTime

B4X:
Activity_Resume
    If mFirstTime Then
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.
 
Upvote 0
D

Deleted member 103

Guest
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!
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
I would like to know if only my device has the error or is a mistake of Samsung.
Samsung J5 2017, Android 8.0
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
@Filippo sorry for the delay, I saw only now, I've been busy
Logger connesso a: 7BKDU17616008699
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true *
** Activity (main) Resume **

Honor 9 - Android 8.0
 
Upvote 0
Top