Delpher2600 0 Posted February 14, 2023 (edited) Hi. I am making Android app, and i add Android Service to project, guided by this video: Code in the Android Service: unction TDM.AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer; begin Result := TJService.JavaClass.START_STICKY; end; Calling from main project: FService : TLocalServiceConnection; FService := TLocalServiceConnection.Create; FService.StartService('F'); But when i lainch my application, it is crashing at once at start. When i launch my app under debugging, Delphi writing me: Quote raised exception class EJNIException with message Full text on the attachment. Also, debugger get this code: Quote {$IFDEF ANDROID} procedure DoRaiseJNIExceptionCallBack(const JNIExceptionClassName: string; const Msg: string); begin raise EJNIException.CreateWithClassName(JNIExceptionClassName, Msg); end; {$ENDIF} Quote procedure TPlatformAndroid.UnbindAppGlueEvents; var AndroidAppGlue: TAndroidApplicationGlue; begin AndroidAppGlue := PANativeActivity(System.DelphiActivity)^.instance; if AndroidAppGlue <> nil then begin AndroidAppGlue.OnApplicationCommandEvent := nil; AndroidAppGlue.OnContentRectEvent := nil; AndroidAppGlue.OnInputEvent := nil; end; end; I am using Delphi 10.4 CE. Edited February 14, 2023 by Delpher2600 Share this post Link to post
Dave Nottage 552 Posted February 15, 2023 1 hour ago, Delpher2600 said: Calling from main project: That doesn't show where in the project the code is executed. In later versions of Android, you a service needs to be started when the application is in the foreground, so you may need to execute the code that starts it in the OnShow event of the main form, or possibly add a listener for the BecameActive application event, and execute it then. Also, this code: 1 hour ago, Delpher2600 said: FService.StartService('F'); Does not match the exception in the image, since 'Z' <> 'F'. I assume a typo, or you renamed the service. Share this post Link to post
Delpher2600 0 Posted February 15, 2023 5 minutes ago, Dave Nottage said: n later versions of Android, you a service needs to be started when the application is in the foreground, so you may need to execute the code that starts it in the OnShow event of the main form, or possibly add a listener for the BecameActive application event, and execute it then. How make it? 5 minutes ago, Dave Nottage said: I assume a typo, or you renamed the service. Yes, it's was renamed. Share this post Link to post
Dave Nottage 552 Posted February 15, 2023 1 minute ago, Delpher2600 said: How make it? Are you saying you do not understand this part? 2 minutes ago, Delpher2600 said: you may need to execute the code that starts it in the OnShow event of the main form Share this post Link to post
Delpher2600 0 Posted February 15, 2023 1 minute ago, Dave Nottage said: Are you saying you do not understand this part? 1 minute ago, Dave Nottage said: you may need to execute the code that starts it in the OnShow event of the main form I'm using this code: FService : TLocalServiceConnection; FService := TLocalServiceConnection.Create; FService.StartService('F'); In OnTimer of TTimer. So, i think not if using OnShow may change somebody. Share this post Link to post