Hi everyone, i'm taking a look to @Erel example on Geofence
(https://www.b4x.com/android/forum/t...ing-a-region-in-the-background.84767/#content).
I'm trying to change it in order to implement it as foreground service, in this way TEORICALLY the OS can't kill my process (after months i didn't achieve this result yet).
The problem is that i scheduled the geofencing service to start every 5 minutes and automaticforeground stops after he return a result, BUT this work only the first time, the second time it doens't respond.
I put this in Service_Create
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
This in Service_Start
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
+ the CreateNotification Sub
This at the end of the Service_Start
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
And this in Service_Destroy
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The rest is the same as in the example linked before.
What's wrong?
I leave the project in the attached file.
Thank in advance
			
			(https://www.b4x.com/android/forum/t...ing-a-region-in-the-background.84767/#content).
I'm trying to change it in order to implement it as foreground service, in this way TEORICALLY the OS can't kill my process (after months i didn't achieve this result yet).
The problem is that i scheduled the geofencing service to start every 5 minutes and automaticforeground stops after he return a result, BUT this work only the first time, the second time it doens't respond.
I put this in Service_Create
			
				B4X:
			
		
		
		lock.PartialLock
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVERThis in Service_Start
			
				B4X:
			
		
		
		    Service.StartForeground(1, CreateNotification("Controllo..."))
StartServiceAtExact(Me, DateTime.Now + Freq*DateTime.TicksPerMinute, True)This at the end of the Service_Start
			
				B4X:
			
		
		
		Service.StopAutomaticForegroundAnd this in Service_Destroy
			
				B4X:
			
		
		
		lock.ReleasePartialLockThe rest is the same as in the example linked before.
What's wrong?
I leave the project in the attached file.
Thank in advance
Attachments
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							 
				 
 
		 
 
		 
 
		 
 
		