Delphi 10 Seattle Update1如何从主机应用程序停止服务

时间:2016-02-20 19:08:20

标签: android delphi service delphi-10-seattle

我使用Delphi 10 Seattle update1,我有一个Android服务,我从主机应用程序开始,但我不知道如何从主机应用程序停止服务。有人可以告诉我吗?

1 个答案:

答案 0 :(得分:2)

您正在使用该服务启动该服务 TLocalServiceConnection.StartService()方法。 Embarcadero不提供相应的TLocalServiceConnection.StopService()方法,因此您必须直接调用Android Context.stopService()方法。

以下是来自TLocalServiceConnection.startService()的{​​{1}}的源代码:

$(BDS)\source\rtl\android\System.Android.Service.pas

您可以将class procedure TLocalServiceConnection.StartService(const AServiceName: string); var LIntent: JIntent; LService: string; begin LIntent := TJIntent.Create; LService := AServiceName; if not LService.StartsWith('com.embarcadero.services.') then LService := 'com.embarcadero.services.' + LService; LIntent.setClassName(TAndroidHelper.Context.getPackageName(), TAndroidHelper.StringToJString(LService)); TAndroidHelper.Activity.startService(LIntent); end; 替换为TAndroidHelper.Activity.startService()

TAndroidHelper.Activity.stopService()
相关问题