Android Question [SOLVED] Why Activity_Create is executed 2 times ?

vbmundo

Well-Known Member
Licensed User
Hi,

I don't undertand why for every Activity, Android or B4A run 2 times Activity_Create..

I put code there, and this code is executed 2 times.

Regards
 

vbmundo

Well-Known Member
Licensed User
I don't understand.. in my 2 APPs... for every Activity I see

** Activity (Anyone) Create, isFirst = true **
xxx
xxx
xxx
** Activity (Anyone) Create, isFirst = false **

And as Layout is loaded in every Create instance, I need to repeat all code

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Look Don,

this is my log

B4X:
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (mysql) Create **
** Service (mysql) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysql) Start **
Raising.. schema_status
Connected to Database
** Activity (main) Pause, UserClosed = false **
** Activity (listatablas) Create, isFirst = true **
** Activity (listatablas) Resume **
** Activity (listatablas) Pause, UserClosed = false **
** Activity (querymanager) Create, isFirst = true **
** Activity (querymanager) Resume **
** Activity (querymanager) Pause, UserClosed = false **
** Activity (query) Create, isFirst = true **
** Activity (query) Resume **
MySQL Database not connected!
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
Raising.. tables_status
Connected to Database
** Activity (query) Pause, UserClosed = false **
** Activity (resultadoselect) Create, isFirst = true **
** Activity (resultadoselect) Resume **
** Activity (resultadoselect) Pause, UserClosed = false **
** Activity (resultadoselect) Create, isFirst = false **
SELECT * FROM channels - TablesSQL
** Activity (resultadoselect) Resume **
** Service (starter) Destroy **
** Service (mysql) Destroy **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

And this is my Code

B4X:
Sub Activity_Create(FirstTime As Boolean)
       Activity.LoadLayout("ResultadoSELECT")
    f.Initialize
    Telefono.SetScreenOrientation(0)
    Activity.Title=" Query Results"
    BotonSiguiente.Visible=False
    BotonPrevio.Visible=False
    Barra.SetAsActionBar
    Barra.InitMenuListener
    ABHelper.Initialize
    ABHelper.ShowUpIndicator = True
    Activity.AddMenuItem("Save Query","GrabarQuery")  
    Activity.AddMenuItem("Show the SQL Statement","ShowSQL")
    Activity.AddMenuItem("Export","Export")
    MySQL.CorroSQL=True
    If FirstTime=False Then
           ProgressDialogShow2("Running SQL",False)
        CallSub2(MySQL,"LeoMySQLTables",CreateMap("TextoSQL":MySQL.TextoSQL,"Activity":"ResultadoSELECT","Modulo":"TablesSQL"))
    End If
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        StateManager.ResetState("ResultadoQUERY")
        Telefono.SetScreenOrientation(-1)
        Activity.Finish
    Else
        StateManager.SaveState(Activity, "ResultadoQUERY")
    End If
    StateManager.SaveSettings
End Sub

all MySQL calls, are using your lib.

thanks
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
SetScreenOrientation should only be used if you want to change the orientation at runtime. You should instead change the #SupportedOrientations attribute.

Thanks Erel,

But I need to set some Activitys with PORTRAIL and just one LANDSCOPE

I see that #SupportedOrientations is for the entire APP

How can I set ONE only Activity as LANDSCOPE but without runs Create Sub 2 times ?

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi Pablo,

if you do not want to change the manifest manually, you can do this in the activity you want landscape:

B4X:
Sub Globals
Dim Phone1 As Phone
' .............
' .............
' .............

Sub Activity_Create(FirstTime As Boolean) 
  Phone1.SetScreenOrientation(0) ' landscape
' .............
' .............
' .............

Sub Activity_Pause (UserClosed As Boolean)

if UserClosed then Phone1.SetScreenOrientation(-1)  ' unlock screen rotation
' .............
' .............
' .............

regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Yes Jesus,

All my Activitys has this SetScreenOrientation() statement.

but if you read this thread you will understand that the command is executed, the SUB Create running again ... which makes very little-productive

You can test this.. include this statement in your CREATE sub and see your log section.

NOW... I have this settings in the Manifest and all runs more faster because my CREATE Subs runs once

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi Pablo



All my Activitys has this SetScreenOrientation() statement.
That is the mistake, only you would have to put in which is landscape.
How can I set ONE only Activity as LANDSCOPE but without runs Create Sub 2 times ?


but if you read this thread you will understand that the command is executed, the SUB Create running again ... which makes very little-productive
It is logical that reenters Create, are forcing a change of orientation, although this change is by code.

I just said if ...
f you do not want to change the manifest manually


Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Not really Jesus,

Because, If you have a Layout that only works in Portrait, you must to set this value as the unique possible value.

Regards

Yes that always works, but in your code you add this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("ResultadoSELECT")
    f.Initialize
    Telefono.SetScreenOrientation(0)  ' <-- This causes rotate and re-enters in create

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User

Yes, now I have all in Manifest and works fine.

Regards
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…