Android Question High battery usage Application ?

Waldemar Lima

Well-Known Member
Licensed User
hi !

this are all resurces what my application using ...

B4X:
Sub Process_Globals

    Public server As Socket ' connect to tcp server
    Public AStreams As AsyncStreams
    Dim ApplicationPass As Int = 0
    Dim ConnectTimeOut As Int = 0
    Dim ApplicationCode As String = ""
    Public GPS1 As GPS ' verify if GPS is enabled
    
End Sub

Sub Globals
    
    'Gmaps Screen
    Private gmap As GoogleMap ' using gmaps
    Private MapFragment1 As MapFragment
    Private Button1 As Button
    Private Button1_n As Button
    Private Button2_n As Button
    Private Button3_n As Button
    Private Button4_n As Button
    Private bmp As Bitmap
    Private cp As CameraPosition
    Private MenuIsVisible As Int
    'Main Screen
    Private ImageView1 As ImageView
    Private Panel1 As Panel
    Private Button1_Acess As Button
    Private Label1_acesscode As Label
    Private EditText1_acesscode As EditText
    
End Sub
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
well , still high battery usage :c

Main code =
B4X:
#Region  Project Attributes
   #ApplicationLabel: Bus Tracker
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
    #AdditionalJar: com.google.android.gms:play-services-maps

#End Region

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

'Activity module
Sub Process_Globals

End Sub

Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Please install Google Play Services.", True)
    End If
    
End Sub

Sub MapFragment1_Ready
    gmap = MapFragment1.GetMap
    Dim m1 As Marker = gmap.AddMarker(10, 30, "test")
    m1.Snippet = "This is the snippet"
End Sub

Sub Activity_Resume
    Starter.GPS1.Start(0,0)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Starter.GPS1.Stop
End Sub


Starter code :

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: 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.
    Public server As Socket
    Public AStreams As AsyncStreams
    Public GPS1 As GPS
    
End Sub

Sub Service_Create
    
    GPS1.Initialize("GPS1")
    server.Initialize("server")
    server.Connect("192.168.1.4",5562,5000)

End Sub

Sub Service_Start (StartingIntent As Intent)
    If (GPS1.IsInitialized = True) Then
        If GPS1.GPSEnabled = False Then
            ToastMessageShow("Por favor , ative o GPS !", True)
            StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
        End If
    Else
        Msgbox("Não foi possível inicializar o GPS .","Erro ao iniciar GPS.")
        ExitApplication
    End If
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

Sub server_Connected (Successful As Boolean)
    If (Successful = True ) Then
        Log("Connectado !")
    End If
End Sub


What is causing the high usage of the battery is the GPS?
 
Upvote 0
Top