I used the Application.ProcessMessages command in my windows application to keep the application breathing.
Don't do that. It is always a sign of bad UI/code design.
I'm looking for an alternative method for the Android application.
Redesign your approach, for all platforms, even Windows.
First off, you should not call Randomize() more than once per process. Call it at program startup.
Second, and most importantly, don't block the UI thread for lengthy operations. ESPECIALLY important on mobile platforms, but even for desktop platforms, too. UI painting is done frequently and should be fast. If your painting is so slow that the user notices it, and the OS thinks the app is unresponsive because of it, then move the actual drawing to a worker thread instead, and have it draw onto an in-memory bitmap, and then notify the UI thread whenever a new bitmap is ready for use so it can trigger a repaint. Every time the UI needs to be painted, let the UI thread paint by simply drawing the latest bitmap onto the UI, and keep that bitmap around for subsequent paints until a new bitmap is ready.
For example (may need tweaking to suit your needs, but you should get the idea):
type
TDrawingThread = class(TThread)
private
FBitmap: TBitmap;
FOnNewBitmap: TNotifyEvent;
procedure NewBitmapReady;
protected
procedure Execute; override;
public
constructor Create(Width, Height: Integer); reintroduce;
destructor Destroy; override;
property Bitmap: TBitmap read FBitmap;
property OnNewBitmap: TNotifyEvent read FOnNewBitmap write FOnNewBitmap;
end;
constructor TDrawingThread.Create(Width, Height: Integer);
begin
inherited Create(True);
FBitmap := TBitmap.Create;
FBitmap.Width := Width;
FBitmap.Height := Height;
end;
destructor TDrawingThread.Destroy;
begin
FBitmap.Free;
inherited;
end;
procedure TDrawingThread.Execute; override;
begin
while not Terminated do
begin
FBitmap.Canvas.Lock;
try
FBitmap..Canvas.Brush.Color := clBlack;
FBitmap..Canvas.FillRect(Rect(0, 0, FBitmap.Width, FBitmap.Height));
for i := 0 to FBitmap.Width-1 do
begin
FBitmap.Canvas.Pen.Color := TColor(Random(144));
FBitmap.Canvas.MoveTo(0, 0);
FBitmap.Canvas.DrawLine(i, FBitmap.Height);
end;
finally
FBitmap.Canvas.Unlock;
end;
if Assigned(FOnNewBitmap) then
Synchronize(NewBitmapReady);
end;
end;
procedure TDrawingThread.NewBitmapReady;
begin
if Assigned(FOnNewBitmap) then
FOnNewBitmap(Self);
end;
var
DrawingThread: TThread;
CurrentBitmap: TBitmap;
procedure TAndroidModule1.ModuleCreate(Owner: TComponent);
begin
Randomize;
CurrentBitmap := TBitmap.Create;
DrawingThread := TDrawingThread.Create(5000, jDrawingView1.Height);
DrawingThread.OnNewBitmap := NewBitmapReady;
DrawingThread.Resume;
end;
procedure TAndroidModule1.NewBitmapReady(Sender: TObject);
begin
CurrentBitmap.Assign(DrawingThread.Bitmap);
jDrawingView1.Invalidate;
end;
procedure TAndroidModule1.jDrawingView1Draw(Sender: TObject; countXY: integer;
X: array of single; Y: array of single; flingGesture: TFlingGesture;
pinchZoomScaleState: TPinchZoomScaleState; zoomScale: single);
begin
// draw CurrentBitmap onto jDrawingView1 as needed...
end;