简体   繁体   中英

Locationsensor does not turn off

I'm using a locationsensor that is active on formcreate and a Mapview with Compass and MyLocation ControlOptions turned on on design time. I want to turn the location off when the app goes to background. I use this code:

function Frm.OnApplicationEvent(AAppEvent:TApplicationEvent;AContext:TObject):Boolean;
var
StartupIntent: JIntent;
  begin    
    case AAppEvent of
      TApplicationEvent.EnteredBackground:
      //TApplicationEvent.willbecomeinactive:
       begin
        MapView1.ControlOptions := MapView1.ControlOptions - [TMapControlOption.MyLocation];
        MapView1.ControlOptions := MapView1.ControlOptions - [TMapControlOption.Compass];
        locationsensor1.Active:=false;
        mapview1.Enabled:=false;
       end;
      TApplicationEvent.WillBecomeForeground:
       begin
        mapview1.Enabled:=true;
        MapView1.ControlOptions := MapView1.ControlOptions + [TMapControlOption.MyLocation];
        MapView1.ControlOptions := MapView1.ControlOptions + [TMapControlOption.Compass];
        locationsensor1.Active:=true;
       end;
    end;
    Result := False;
  end;

but the location icon on android does not disappear. It only disappear if I kill the app.

Any idea of the problem?

Thanks a lot

The problem was the MapView. If I put the visibility of the container of the mapview (a panel) to false, then locationsensor goes to disabled when going to background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM