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
Sorry for this obvious answer but resume is executed 2 times because Main is paused; you should discover why.
** Activity (main) Pause, UserClosed = false **
What should be the reason for this? The code above is everything, there is only this one MsgBox. :(
Please try it.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I forgot to ask you if you are using b4a 8.30 beta :)

Unfortunately I can not try on Android 8.0.

Did you set the project orientation (#SupportedOrientations: unspecified)?

I have a problem with my new phone because it is always in portrait and my app in landscape.
 
Upvote 0
D

Deleted member 103

Guest
Log from Nexus 7 (Android 5.1):
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

Log from Smasung A5(2017) Android 8.0:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

Log from HTC-one-A9(Android 7.1):
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 
Upvote 0
D

Deleted member 103

Guest
so the problem is right on Android 8 (if you have not changd #SupportedOrientations: unspecified).

That's the whole code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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

udg

Expert
Licensed User
Longtime User
Could it be because the Msgbox2Async wakes up again Resume when its result it's available?

From Message2Async definition:
B4X:
Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null, False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
  '...
End If

In your code I can't see any reference to Msgbox_Result
 
Upvote 0
D

Deleted member 103

Guest
Could it be because the Msgbox2Async wakes up again Resume when its result it's available?

From Message2Async definition:
B4X:
Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null, False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
  '...
End If

In your code I can't see any reference to Msgbox_Result

B4X:
Sub Activity_Resume
    Msgbox2Async("Message", "Titel", "OK", "", "", Null, False)
    Wait For Msgbox_Result (Result As Int)
    If Result = DialogResponse.POSITIVE Then
        Log("Result=" & Result)
    End If
Log from Smasung A5(2017) Android 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
So, no improvement! :(
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Per il momento ti consiglierei una cosa ovvia, non usare la versione asincrona del msgbox!
Per una risposta "risolutiva" dovremo aspettare Erel; è chiaro, oramai, che il problema esiste solo con Android 8+.


For the moment I would recommend something obvious, do not use the asynchronous version of msgbox!
For a "decisive" answer we will have to wait for Erel; it is clear, now, that the problem exists only with Android 8+.
 
Upvote 0
D

Deleted member 103

Guest
Log from Smasung A5(2017) with Android 8.0 and B4a 8.30-Beta:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Result=-1
I do not know if it's a B4a bug or an Android bug, only Erel can tell us.
 
Upvote 0
D

Deleted member 103

Guest
Log with normale MsgBox:
B4X:
Sub Activity_Resume
    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

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

LucaMs

Expert
Licensed User
Longtime User
Log with normale MsgBox:
B4X:
Sub Activity_Resume
    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
That's incredible! Wich b4a version? (try both).

Try setting the orientation, 2 tests, portrait and landscale (sync msgbox).
 
Upvote 0
Top