1

I wrote an android geofence app for commercial businesses, and put it all into the service that I send to the foreground to trigger a business detection notification when entering a specific enclosed perimeter.

Thanks to the service I send to Foreground, it works great, even with the app closed and phone lock screen.

The code for service in foreground it is:

var
    LBuilder: JNotificationCompat_Builder;
    MyNotification: TNotification;
begin
    if FNotificationChannel = nil then CreateNotificationChannel;
    JavaService.stopForeground( True );
    LBuilder := TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context, 
      TAndroidHelper.Context.getPackageName );
    LBuilder.setAutoCancel( True );
    LBuilder.setContentTitle( StrToJCharSequence( 'GeoLocation' ) );
    LBuilder.setContentText( StrToJCharSequence( 'GeoLocation in monitoraggio' ) );
    LBuilder.setSmallIcon( TAndroidHelperEx.GetDefaultIconID );
    LBuilder.setTicker( StrToJCharSequence( 'GeoLocation' ) );
    JavaService.StartForeground( 2096, LBuilder.build );

I took many walks, and the notification always sendfor the test perimeters I had set up: a bar, a supermarket, a tobacconist, etc.

I only have this problem:

In the service I use a global variable: which I called "strpreviousname", in order not to continuously trigger the company detection notification, every time the locationsensor changes and when I'm always within that perimeter

However, I have seen that despite the variable set, the notification starts equally both when I close the app and when I lock the phone screen.

So it's like, every time I close the app, or turn off the phone, the service restarts each time, resetting the strpreviousname global variable, and thus making it redeem the detection notification again.

Do you happen to know why?

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
Valerio
  • 49
  • 4

0 Answers0