Application.ProcessMessages command, what is the alternative on android? lazarus / 43-Android ---------------------------------------------------------------------- loaded · 2019-02-14 08:07 Hello to everyone, I used the Application.ProcessMessages command in my windows application to keep the application breathing. I'm looking for an alternative method for the Android application. Thank you in advance for your help. Example Code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.jDrawingView1Draw(Sender: TObject; countXY: integer;  X: array of single; Y: array of single; flingGesture: TFlingGesture;  pinchZoomScaleState: TPinchZoomScaleState; zoomScale: single);begin   randomize;   jDrawingView1.BackgroundColor:=colbrBlack;   for i:=0 to 5000 do // ~100000 do   begin   jDrawingView1.PaintColor:=TARGBColorBridge(Random(144));   jDrawingView1.DrawLine(0,0,i,jDrawingView1.Height);   //Application.ProcessMessages;   end;end; ---------------------------------------------------------------------- Remy Lebeau · 2019-02-14 18:15 Quote from: loaded on February 14, 2019, 09:07:21 amI 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. Quote from: loaded on February 14, 2019, 09:07:21 amI'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): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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; ---------------------------------------------------------------------- Handoko · 2019-02-14 18:42 Quote from: loaded on February 14, 2019, 09:07:21 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    for i:=0 to 5000 do // ~100000 do   begin  If you have high amount of items needed to draw on the screen, it is usually good to use a buffer. Not sure about Android. On PC, drawing on the screen directly is slow. So we draw all the items on a buffer and copy the buffer to the screen in one single pass. This trick can reduce flickering and improve performance. You can learn more about using buffer here (PC version): https://forum.lazarus.freepascal.org/index.php/topic,38136.msg263143.h tml#msg263143 ---------------------------------------------------------------------- loaded · 2019-02-14 19:02 Remy Lebeau and Handoko Thank you for taking your precious time and writing your answer. I understand that I have to work more.