Locationsensor没有关闭

时间:2018-02-20 21:09:54

标签: android delphi firemonkey

我正在使用在formcreate上处于活动状态的locationsensor,并且在设计时打开了带有Compass和MyLocation ControlOptions的Mapview。我想在应用程序转到后台时关闭该位置。我使用这段代码:

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;

但android上的位置图标不会消失。它只会在我杀死应用程序时消失。

对这个问题有什么想法吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

问题是MapView。如果我将mapview(面板)的容器的可见性设置为false,那么locationsensor在转到后台时会被禁用。

相关问题