Android Question Geofence foreground doesn't Work

Mike1970

Well-Known Member
Licensed User
Longtime User
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

B4X:
lock.PartialLock
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER


This in Service_Start

B4X:
    Service.StartForeground(1, CreateNotification("Controllo..."))
StartServiceAtExact(Me, DateTime.Now + Freq*DateTime.TicksPerMinute, True)
+ the CreateNotification Sub

This at the end of the Service_Start
B4X:
Service.StopAutomaticForeground

And this in Service_Destroy
B4X:
lock.ReleasePartialLock

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
 

Attachments

  • Geofence_Foreground_Test.zip
    8.9 KB · Views: 227
Last edited:

DonManfred

Expert
Licensed User
Longtime User
The problem is that i scheduled the geofencing service to start every 5 minutes
You got told (multiple times) that you are not allowed to restart a service in this interval! Android (at least higher SDKs) does NOT allow it.

Why you are still trying it?
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
You got told (multiple times) that you are not allowed to restart a service in this interval! Android (at least higher SDKs) does NOT allow it.

Why you are still trying it?
Because even if i restart every 30 MINUTES it doesn’t work!
I already told ! Ok?


In the GPS post someone said that to him checking every 30 minutes worked for 6 days and more, to me less than 11 Hours...

46290DCC-5700-406A-9CBC-1133F1C8938C.jpeg


It is obvious that there is something else to be spotted, do you agree??
 
Last edited:
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top