Hi,
I have read a lot of posts to this subject but still I can't resolve my issue.
I have the following code that sends the battery level to a PHP skript in the internet.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
But it still occasionally misses to fire the event. Also when stoping and restarting the service it does simply not allways fire. Even when starting the service in foreground it sometimes misses. What can this be? Is the Andriod system so inreliable on this?
The startserviceat is just a failsafe incase the level doesnt actually change for some time. But this is not the cause, neither is that I check the last value to the current. I have checked that.
			
			I have read a lot of posts to this subject but still I can't resolve my issue.
I have the following code that sends the battery level to a PHP skript in the internet.
			
				B4X:
			
		
		
		#Region  Service Attributes
    #StartAtBoot: true
#End Region
Sub Process_Globals
    Dim hc As HttpClient
    Dim pe As PhoneEvents
    Dim last As Int
End Sub
Sub Service_Create
    Dim n As Notification
    n.Initialize
    n.AutoCancel = False
    n.OnGoingEvent = True
    n.Vibrate = False
    n.Sound = False
    n.Light = False
    n.Icon = "icon"
    n.SetInfo("BatMon", "starting", Main)
    last = 0
    Service.StartForeground(1, n)
    hc.InitializeAcceptAll("hc")
    pe.Initialize("pe")
End Sub
Sub Service_Start (StartingIntent As Intent)
    pe.Initialize("pe")
End Sub
Sub Service_Destroy
    Service.StopForeground(1)
    Dim n As Notification
    n.Initialize
    n.Cancel(1)
    pe.StopListening
End Sub
Sub pe_BatteryChanged(Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
    If last = Level Then
        StartServiceAt(Me, DateTime.Now + (DateTime.Ticksperhour * 4), True)
        Return
    End If
    Dim n As Notification
    n.Initialize
    n.AutoCancel = False
    n.OnGoingEvent = True
    Dim so As Boolean = False
    If Level < 10 Then     so = True
    n.Vibrate = so
    n.Sound = so
    n.Light = False
    n.Icon = "icon"
    n.SetInfo("BatMon", Level & "%", Main)
    n.Notify(1)
    last = Level
    upload(Level)
    StartServiceAt(Me, DateTime.Now + (DateTime.TicksPersecond * 4), True)
End Sub
Sub upload(level As Int)
    StartServiceAt(Me, DateTime.Now + (DateTime.Ticksperhour * 6), True)
    Dim hr As HttpRequest
    hr.InitializeGet("http://www.somesite.com/battery.php?lv=" & level & "&id=" & File.ReadString(File.DirInternal, "id.txt"))
    hc.Execute(hr, 1)
End Sub
Sub hc_ResponseSuccess (response As HttpResponse, TaskId As Int)
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
End Sub
	But it still occasionally misses to fire the event. Also when stoping and restarting the service it does simply not allways fire. Even when starting the service in foreground it sometimes misses. What can this be? Is the Andriod system so inreliable on this?
The startserviceat is just a failsafe incase the level doesnt actually change for some time. But this is not the cause, neither is that I check the last value to the current. I have checked that.