One of customers complaining app starting up every 30 minutes. I have not able to duplicate it. Is there any flaws in the code below which can startup the Main?
B4X:
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
tmrTrip.Initialize("tmrTrip", 500) 'every 500 milliseconds
tmrTripSaveData.Initialize("tmrTripSaveData", 60000) '1 minutes
GPS1.Initialize("GPS")
PhoneEvent.Initialize("PhoneEvents")
StateManager.LoadStateTrip 'load these
StateManager.LoadStateMaintenance 'load these at first startup
StateManager.LoadStateSpeedLimiter 'load speed limiter value
CheckPreferenceState
Starter.pws.PartialLock 'Important so it will not CPU Sleep
TripIcon1 = LoadBitmapResize(File.DirAssets, "tripicon.png", 24dip, 24dip, True)
TripIcon2 = LoadBitmapResize(File.DirAssets, "mainicon.png", 24dip, 24dip, True)
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True) '30 minutes
If StateManager.blnUseGPS = True Then
Log("Timer and Notification turned on in START..")
Service.StartForeground(1, CreateNotification("..."))
CallCreateNotification("...", "")
TurnOnTmrTrip
End If
'not used. used for tracking buttons in notification
' If StartingIntent.IsInitialized Then
' Log(StartingIntent.Action)
' End If
End Sub
B4X:
Sub CheckPreferenceState
Try
Dim m1 As Map
m1.Initialize
'file exists then get value
If File.Exists(File.DirInternal, Starter.PrefFile) = True Then
m1 = File.ReadMap(File.DirInternal, Starter.PrefFile)
Dim WhatValue As String = m1.Get("prefUseGPS")
Dim WhatisMph As String = m1.get("MphUnit")
Dim WhatACCharger As String = m1.Get("prefACCharger")
Dim WhatBatterySaveMode As String = m1.Get("prefBatterySaveMode")
Dim WhatBatterySaveModeTime As String = m1.Get("prefBatterySaveModeTime")
Dim WhatSpeedDecimal As String = m1.Get("GPSSpeedDecimal")
Dim WhatMphGPS As String = m1.Get("MphUnitGPS")
If WhatValue = "null" Or WhatValue = "" Then 'Use Gps
StateManager.blnUseGPS = True 'default if null
Else
StateManager.blnUseGPS = WhatValue
End If
If WhatBatterySaveMode = "null" Then 'Battery Save Mode
StateManager.blnBatterySaveModeTrip = True 'default if null
Else
StateManager.blnBatterySaveModeTrip = WhatBatterySaveMode
End If
If WhatBatterySaveModeTime = "null" Then 'Battery Save Mode Time
StateManager.intBatterySaveModeCheckTime = 120 'default if null
Else
StateManager.intBatterySaveModeCheckTime = WhatBatterySaveModeTime
End If
If WhatACCharger = "null" Then 'Charger Type Mode
StateManager.blnACChargerPluggedIn = False 'default if null
Else
StateManager.blnACChargerPluggedIn = WhatACCharger
End If
If WhatisMph = "null" Then 'Mph or Km/h
StateManager.isMph = False 'default if null
Else
StateManager.isMph = WhatisMph
End If
If WhatSpeedDecimal = "null" Then '(speed # decimals to show)
StateManager.GPSSpeedDecimal = 0 'default if null
Else
StateManager.GPSSpeedDecimal = WhatSpeedDecimal
End If
If WhatMphGPS = "null" Then '(feet or meters)
StateManager.isMphGps = False 'default if null
Else
StateManager.isMphGps = WhatMphGPS
End If
' Log("USE GPS: " & StateManager.blnUseGPS)
' Log("Battery Save Mode: " & StateManager.blnBatterySaveModeTrip)
' Log("Battery Save Mode Time: " & StateManager.intBatterySaveModeCheckTime)
' Log("Plugged In: " & StateManager.blnACChargerPluggedIn)
' Log("MPH: " & StateManager.isMph)
' Log("Decimal: " & StateManager.GPSSpeedDecimal)
' Log("GPS Feet: " & StateManager.isMphGps)
'file does not exist then set default to true
Else
StateManager.blnUseGPS = True
StateManager.isMph = False
StateManager.blnACChargerPluggedIn = False
StateManager.blnBatterySaveModeTrip = True
StateManager.intBatterySaveModeCheckTime = 120
StateManager.GPSSpeedDecimal = 0
StateManager.isMphGps = False
End If
Catch
Log(LastException)
StateManager.blnUseGPS = True
StateManager.isMph = False
StateManager.blnACChargerPluggedIn = False
StateManager.blnBatterySaveModeTrip = True
StateManager.intBatterySaveModeCheckTime = 120
StateManager.GPSSpeedDecimal = 0
StateManager.isMphGps = False
End Try
End Sub