Tempo para começar (START) o aplicativo

jeronimovilar

Active Member
Licensed User
Longtime User
Ao clickar/tocar no meu app leva 3 segundos para para o título do aplicativo aparecer na tela e mais 5 segundos.
Tentei colocar LOG para verificar cada tempo, mas para aparecer o primeira já demora muito.
Não sei se teria outra forma de verificar o tempo que cada serviço ou processo leva para iniciar.
Segue o codigo do inicio do aplicativo (utilizo algumas retiradas de exemplos do FORUM):
B4X:
#Region  Project Attributes 
    #ApplicationLabel: SBTY-Tablet
    #VersionCode: 6
    #VersionName: 6.0.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: true
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    LogColor("*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*x*x*x*x", Colors.green)
    Log("Main Procces Global: " & DateTime.Time(DateTime.Now))
    ToastMessageShow("Carregando....",False)
   
    Dim ServerUrl, IP As String
    Dim p As Phone   
    Dim Timer1  As Timer
    IP = "192.168.0.100"
    Private nativeMe As JavaObject
   
    Dim CountDown1 As Int
    Dim CountDown2 As Int
    Dim mp As MediaPlayer
    Dim vibrate As PhoneVibrate
    Dim Tot_Camisas, Tot(6,6), CodJuiz, PORTA As Int
   
    Dim FadeTimer As Timer
'    Dim First As Boolean
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.
    Log("MAIN Globals: " & DateTime.Time(DateTime.Now))
    '------------botão redondo -------------
    Dim b1 As Button
    Dim p1 As Panel
    Dim mb1 As circleButton
    Dim bm1, bmSOM As Bitmap
    '---------------------------------------
    Dim btnNota(6,16), btnCamisa(6), btnFecha As Button

    Dim Fator As Int    ' = 80
    Dim OndaGrava, CamisaGrava As Int = 0
    Dim TxtDigita As Label
    Dim NotaGravar As Double
    Dim VarLinguagem, SQL As String
    Dim LblCmsNota, lblNaAgua As Label
   
    Dim Vermelha, Branca, Amarela, Azul, Verde, Preta, Cinza As Int  ' Cores das Lycras
    Dim corBorda As ColorDrawable
    Dim Bat, Cat, Fase, Categoria, TEMPO, MOSTRA As String
    Dim GravarJuiz, AlterarPorta, ApagaResumo, AlterarJuiz, Medias As Boolean
    Dim Cor_CMS(6), InterfOnda(6,16) As String
    Dim IncluirAlterar As String = "I"
    Dim x2 As String
   
    '-----------------------------CRIADOS no DESIGNER --------------------------------------------------------------------
    Private panel1 As Panel
'Private SVContagem As ScrollView2D
    Private b60x60 As Button
    'Private SVNotas As ScrollView2D
'Private SVRodape As ScrollView2D
    Private SVCamisas As ScrollView2D
    Private SVNotas As ScrollView2D
    Private Panel2 As Panel
    Private SVTeclado As ScrollView2D
   
    Private b80x80 As Button
    Private b100x100 As Button
    Private Button1 As Button
    Private b90x90 As Button
    Private lblContagem As Label
    Private lblPorta As Label
    Private lblJuiz As Label
    '----------------------------------------------------------------------------------------
    Dim NumPreenche As Int = 1   ' Para saber qual cor das camisas, notas a preencher
    Private btnSOM As Button
   
    Private lblVERSAO As Label
    Private lblTimer As Label
    Private AUDIO As Boolean = False
   
    Dim intFadeCount As Int
    Dim ImageView1 As ImageView
    Dim obj1 As Reflector   
End Sub

Sub GetRealSize As LayoutValues
    Dim lv As LayoutValues
    If p.SdkVersion >= 17 Then
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        Dim display As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window")).RunMethod("getDefaultDisplay", Null)
        Dim point As JavaObject
        point.InitializeNewInstance("android.graphics.Point", Null)
        display.RunMethod("getRealSize", Array(point))
        lv.Width = point.GetField("x")
        lv.Height = point.GetField("y")
    Else
        lv.Width = 100%x
        lv.Height = 100%y
    End If
    lv.Scale = 100dip / 100
    Log("GETREALSIZE: "& lv.Scale)
    Return lv
End Sub

Sub Activity_WindowFocusChanged(HasFocus As Boolean)
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(300)
            jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
        Catch
            'Log(LastException) 'This can cause another error
        End Try 'ignore
    End If
End Sub


Sub addButtonsAndPanels
    b1.Initialize("btn")
    p1.Initialize("")
    panel1.AddView(b1,0,0,0,0)
    panel1.AddView(p1,0,0,0,0)
End Sub

Sub prepButton1
    mb1.Initialize(b1, p1, 0.5%x, 1%y, 28dip, 28dip)
    mb1.setButtonGradientColor(Colors.White, Colors.White)
    mb1.GradientDir = GradDir.BOTTOM_TOP
    mb1.RingColor = Colors.Gray
    mb1.Initialize2(Me,"b1_Click")
    bm1.Initialize(File.DirAssets, "MEDIAS.png")
    mb1.Bitmap = bm1
    mb1.ButtonReaction = Reaction.SHRINK_TO_ZERO_AND_GROW_RADIALLY
    mb1.RingSize = 3dip
    mb1.setButton
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")   
    ' TABLET Carlinhos     - 976 x 600 160DPI
    ' XIAOMI A2         - 2280 x 1080 480 DPI
    ' LG K10             - 320dpi 
    Log("Activity Creat: " & DateTime.Time(DateTime.Now))
    If FirstTime Then
        Log("LayoutSPLASH: " & DateTime.Time(DateTime.Now))
        Activity.LoadLayout("Splash")
        'ImageView1.Initialize("")
        ImageView1.Bitmap = LoadBitmap(File.DirAssets, "Logo_SurfByte-TABLET.png")
        ImageView1.Left = (Activity.Width - 200dip)/2
        ImageView1.Top = (Activity.Height - 200dip)/2
        obj1.Target = ImageView1.Background
        obj1.RunMethod2("setAlpha", 0, "java.lang.int")
        ImageView1.Visible=True
        Log("começar TimerSplach: " & DateTime.Time(DateTime.Now))
        FadeTimer.Initialize("TimerSplash", 50)
        FadeTimer.Enabled = True
        intFadeCount = 0
        '---------------------------------------------------------------------------------------
        Dim p As Phone
        '-----------dimensões -----------
        ' tablet= 976 x 600 (160)
        ' LG K10 - 1193 x 720 (320)
        '--------------------------------
        Dim IP_PING(3) As String
        IP_PING(0) = "192.168.0.100" ' mini ROUTER          '"192.168.43.2"
        IP_PING(1) = "192.168.0.10"    ' Note Luciane
        IP_PING(2) = "192.168.0.11"    '
        IP = "192.168.0.100"

        Dim sb As StringBuilder
        sb.Initialize
        For i2=0 To 2
            p.Shell("ping -c 1 " & IP_PING(i2),Null,sb,Null)
            x2 = sb
            If x2.LastIndexOf("1 received") < 0 Or x2.LastIndexOf("Unreachable") > 0 Then
                x2 = "ERRO! "&IP_PING(i2)
                sb.Remove(0,sb.Length-1)
            Else
                x2 = "OK - "& IP_PING(i2)
                IP = IP_PING(i2)
                Exit
            End If
        Next
        ServerUrl = "http://" & IP & "/base3.asp"
       
        Vermelha = Colors.Red
        Branca = Colors.White
        Amarela = Colors.Yellow
        Verde = Colors.Green
        Azul = Colors.Blue
        Cinza = Colors.Gray
        Preta = Colors.Black
        '---------------------------------------------------------------------------------------
'        ToastMessageShow("Verificando LINGUAGEM..." & IP, False)
        Log("Verificando Linguagem em ..." & IP)
        SQL = "query=select%20LINGUAGEM%20from%20wInternet"
        JobDone2("LINGUAGEM", SQL)
    End If
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
Boas Jeronimo,

Eu começaria por retirar todos os logs, eles te ajudam no momento de codar, mas quando lanças em release, elas pouco te ajudam, e uma vez que estas a desactivar o debugger (#BridgeLogger: False).
Outra coisa que talvez esteja a acontecer aqui, é que enquanto a app prepara o splash screen, o restante codigo pode tambem estar a ser executado, e vejo que tens uma chamada SQL no fim do AppStart. apenas para testar, comenta essa Query para que nao seja executada, e ve se fez diferença.
Uma sugestao seria de tornar o Splash em Libraria, garantindo que no final teria um return true, para poder chama-lo usando o Wait For.
Creio ter sido o user LemonIsDead que criou um Splash bem simples e que pode ser alterado para qualquer finalidade.
 

jeronimovilar

Active Member
Licensed User
Longtime User
Mesmo retirando o SQL não mudou o tempo. Daí descobri que o longo tempo está no momento que descubro o IP do servidor:
B4X:
Log("2- "&DateTime.Time(DateTime.Now))
    Dim sb As StringBuilder
    sb.Initialize
    For i2=0 To 2
        p.Shell("ping -c 1 " & IP_PING(i2),Null,sb,Null)
        x2 = sb
        If x2.LastIndexOf("1 received") < 0 Or x2.LastIndexOf("Unreachable") > 0 Then
            x2 = "ERRO! "&IP_PING(i2)
            sb.Remove(0,sb.Length-1)
        Else
            x2 = "OK - "& IP_PING(i2)
            IP = IP_PING(i2)
            Exit
        End If
    Next
    ServerUrl = "http://" & IP & "/base3.asp"
Log("3- "&DateTime.Time(DateTime.Now))
aproximadamente 4 segundos
vou testar agora o inicio do SPALSH que vc indicou
 

Cableguy

Expert
Licensed User
Longtime User
porque nao usar o servico start para descobrir o IP, assim ele sera feito em paralelo com o resto do codigo
 

jeronimovilar

Active Member
Licensed User
Longtime User
Coloquei enquanto o SPLASH é mostrado. Ficou perfeito. MUITO Obrigado.
Essa semana começo a refazer o Envio de E-mail e qualquer dúvida eu posto aqui.
Os exemplos que peguei utiliza o GMAIL e minha dificuldade tem sido habilitar a permissão para utilizar o GMail através da aplicação
 

Cableguy

Expert
Licensed User
Longtime User
Fico contente de ter ajudado… vai mandando que no que puder, vou ajudando
 
Top