I'm using Delphi 10.1 Berlin.
Everything was OK under XE7.
Now when I start an activity, the result seems to be handled within a thread, and a synchronization/Queue would hang whole application. Since I need to display a TDialogServiceAsync.InputQuery, and if I don't sync, I get an exception telling me I must display my message from the main thread (that was working just perfectly under XE7)
here is the simplified code (tested so) that 'was' working :
Call :
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(
TMessageResultNotification, HandleActivityMessage);
intnt := TJIntent.JavaClass.init;
intnt.setAction(StringToJString('com.domain.mylib.MYCLASS'));
intnt.setPackage(StringToJString('com.domain.mylib'));
TAndroidHelper.Activity.startActivityForResult(intnt, REQUEST_CODE);
Handler :
HandleActivityMessage(const Sender: TObject; const M: TMessage);
begin
// I tried TThread.Sync/Queue here... Hang
if M is TMessageResultNotification then
begin
OnActivityResult(
TMessageResultNotification(M).RequestCode,
TMessageResultNotification(M).ResultCode,
TMessageResultNotification(M).Value
);
end;
end;
OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent);
var
Values: array of String;
begin
if (RequestCode = REQUEST_CODE) and (ResultCode = TJActivity.JavaClass.RESULT_OK) then
begin
//Either
TDialogServiceAsync.ShowMessage('...');
// Or
SetLength(Values, 1);
Values[0] := '';
TDialogServiceAsync.InputQuery('something', ['info'], Values, Self.OnInputQuery2_Close);
end;
end;
With this exception (original and translation...):
'Les messages doivent être affichés dans le thread principal de l'interface utilisateur'
'Messages must be displayed from user interface main thread'