Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Android Service sendcommands make the app not responsive


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Oct 30, 2017 1:21 PM Last Post By: Registered User
madammar ellias

Posts: 111
Registered: 8/17/17
Android Service sendcommands make the app not responsive  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2017 9:07 AM
i am sending some commands from host app to Androice service here is my android service command handler code

function TAndroidServiceDM.AndroidServiceStartCommand(const Sender: TObject;
  const Intent: JIntent; Flags, StartId: Integer): Integer;
begin
 
if (JStringToString(Intent.getAction) = 'StartRead') then
begin
CMDSTART := TRUE;
Exit;
end;
 
 
 
if (JStringToString(Intent.getAction) = 'StopIntent') then
begin
Result := TJService.JavaClass.START_NOT_STICKY;
JavaService.stopSelf;
Exit;
end;
 
Result := TJService.JavaClass.START_NOT_STICKY;
 
ProcessData(Intent);
 
 
end;
 
 
 
 
end;


And here is how i send the Command

LIntent := TJIntent.Create;
LIntent.setClassName(TAndroidHelper.Context.getPackageName(),
TAndroidHelper.StringToJString('com.embarcadero.services.srvapp'));
LIntent.setAction(StringToJString('StartRead'));// here when i chose which action i need to set
TAndroidHelper.Activity.startService(LIntent);


the app is not responsive in startread . what could be the problem ?
Registered User

Posts: 46
Registered: 3/4/05
Re: Android Service sendcommands make the app not responsive  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2017 1:21 PM   in response to: madammar ellias in response to: madammar ellias
I had to copy incoming intents to a queue to process them in the main thread - the lifetime of the intent object may not last enough to be fully processed by the main thread. I had all sorts of glitches until i did this.


madammar ellias wrote:
i am sending some commands from host app to Androice service here is my android service command handler code

function TAndroidServiceDM.AndroidServiceStartCommand(const Sender: TObject;
  const Intent: JIntent; Flags, StartId: Integer): Integer;
begin
 
if (JStringToString(Intent.getAction) = 'StartRead') then
begin
CMDSTART := TRUE;
Exit;
end;
 
 
 
if (JStringToString(Intent.getAction) = 'StopIntent') then
begin
Result := TJService.JavaClass.START_NOT_STICKY;
JavaService.stopSelf;
Exit;
end;
 
Result := TJService.JavaClass.START_NOT_STICKY;
 
ProcessData(Intent);
 
 
end;
 
 
 
 
end;


And here is how i send the Command

LIntent := TJIntent.Create;
LIntent.setClassName(TAndroidHelper.Context.getPackageName(),
TAndroidHelper.StringToJString('com.embarcadero.services.srvapp'));
LIntent.setAction(StringToJString('StartRead'));// here when i chose which action i need to set
TAndroidHelper.Activity.startService(LIntent);


the app is not responsive in startread . what could be the problem ?
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02