I'm just a newbie to the Android application development by Delphi XE5.
During some time-consuming task being processed in the main process, pelt of tapping on the screen (continuously tap the screen over and over again) cause the application's abnormal end.
I guess it is because of so called 'Application Not Responding' and confirm my guess by the code block below.
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Text := 'Start'; // Text is 'Button1' on design time
sleep(10000);
Button1.Text := 'OK';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Button2.Text := 'Start'; // Text is 'Button2' on design time
TThread.CreateAnonymousThread(
procedure()
begin
Sleep(10000);
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
Button2.Text := 'OK';
end);
end).Start;
end;
In the case of the Button1, continuous taps cause ANR. When I restore the App from app stack, the text of Button1 shows 'Button1'. It looks like the process of Button1Click was rewound. On the contrary, in the case of the Button2, continuous tabs won't cause ANR.
I've never used threads in the development of Windows applications. Is it normal way of processing time-consuming tasks in a thread (not in main thread)? Or are there other workarounds?
Threading is the correct solution to this problem. The main thread needs to be responsive if you wish to avoid the system determining that your application is unresponsive. That is just as true for mobile platforms as it is for desktop platforms.
So, move all long running tasks onto threads, and so keep your main thread responsive.