Why do I get an ANR when I close my android App with a service and a TMultiView in drawer-mode

  

my Delphi android app has a sticky service running all the time, and I uses a TMultiView in drawer mode. When I close both the service and the app, I now almost everytime get an ANR after 2-4 minutes, and while waiting on the ANR (the app isn’t visible) I can’t start the app, it only shows the splash screen.
But if I changes the mode for the TMultiView to Panel, I have no problems when closing the app.
I think it startet when I was upgrading to Delphi 11, but I am not sure.
I tried to make a simple test, but it unfortunately only gets an ANR every 5-10 times I close the app, but here is the code for the test:

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.MultiView,

System.Android.Service, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;

type
TForm1 = class(TForm)
mltvw1: TMultiView;
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FService: TLocalServiceConnection;

procedure ServiceConnected(const ALocalService: TAndroidBaseService);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.btn1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
//var
// LIntent: JIntent;
begin
FService := TLocalServiceConnection.Create;
FService.OnConnected := ServiceConnected;

// LIntent := TJIntent.Create;
// LIntent.setClassName(TAndroidHelper.Context.getPackageName(), TAndroidHelper.StringToJString(‘com.embarcadero.services.ServiceTest’));
// TAndroidHelper.Activity.startService(LIntent);

FService.BindService(‘ServiceTest’);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FService.LocalService.JavaService.stopSelf
end;

procedure TForm1.ServiceConnected(const ALocalService: TAndroidBaseService);
begin

end;
end.

And the service

interface

uses
System.SysUtils,
System.Classes,
System.Android.Service,
AndroidApi.JNI.GraphicsContentViewText,
Androidapi.JNI.Os,
Androidapi.JNI.App;

type
TDM = class(TAndroidService)
function AndroidServiceStartCommand(const Sender: TObject;
const Intent: JIntent; Flags, StartId: Integer): Integer;
private
{ Private declarations }
public
{ Public declarations }
end;

var
DM: TDM;

implementation

{%CLASSGROUP ‘FMX.Controls.TControl’}

{$R *.dfm}

function TDM.AndroidServiceStartCommand(const Sender: TObject;
const Intent: JIntent; Flags, StartId: Integer): Integer;
begin
Result := TJService.JavaClass.START_STICKY;
end;

end.

Comments are closed.