Recent

Author Topic: jAsyncTask bug  (Read 823 times)

Segator

  • Full Member
  • ***
  • Posts: 168
    • https://github.com/Nenirey
jAsyncTask bug
« on: April 09, 2021, 01:35:04 pm »
First to all thanks for the continuous lamw improvement, i found that jAsyncTask is not work any more, the demo crash at start and when you tray to use it your app crash too, i think that the problem is about the bridge not found the jAsynk_create  static method.
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

Segator

  • Full Member
  • ***
  • Posts: 168
    • https://github.com/Nenirey
Re: jAsyncTask bug
« Reply #1 on: April 09, 2021, 05:49:30 pm »
the jAsync_Create was an error in my lamw, the realy problem is this:
JNI DETECTED ERROR IN APPLICATION: thread Thread[1,tid=2134,Native,Thread*=0xb0f85400,peer=0x742f2550,"main"] using JNIEnv* from thread Thread

how i can use in a Asynctask a method that use the JNIEnv?
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

Segator

  • Full Member
  • ***
  • Posts: 168
    • https://github.com/Nenirey
Re: jAsyncTask bug
« Reply #2 on: April 09, 2021, 06:01:36 pm »
Or how i can do a method thread safe?
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

neuro

  • Jr. Member
  • **
  • Posts: 62
Re: jAsyncTask bug
« Reply #3 on: July 23, 2022, 07:03:47 pm »
I have tracked down the conditions when jAsyncTask crashes.

https://github.com/jmpessoa/lazandroidmodulewizard/tree/master/demos/GUI/AppAsyncTaskDemo1
Code: Pascal  [Select][+][-]
  1. function  TAndroidModule1.DoTask(Progress: integer): boolean;
  2. begin
  3.   Result:= True; //doing task ...
  4.   if Progress < 100 then
  5.   begin
  6.     Sleep(100 - Progress); //processing task...
  7.   end
  8.   else
  9.     Result:= False; //done !!
  10. end;
  11.  
  12.  
  13. procedure TAndroidModule1.jAsyncTask1ProgressUpdate(Sender: TObject; progress: integer; out progressUpdate: integer);
  14. begin
  15.  
  16.    if progress <= jProgressBar1.Max then
  17.    begin
  18.       jProgressBar1.Progress:= progress;
  19.      // jDialogProgress1.Msg:= 'Lamw: Please, wait... ['+IntToStr(progress)+']';
  20.       progressUpdate:= progress + 1; //out param !
  21.    end
  22.    else
  23.    begin
  24.      jProgressBar1.Progress:= 0;
  25.      //jDialogProgress1.Msg:= 'Lamw: Please, wait...';
  26.      progressUpdate:= 0;  //out param !
  27.    end;
  28.  
  29. end;

AppAsyncTaskDemo1 has two functions:
1) function  TAndroidModule1.DoTask(Progress: integer): boolean;
2) procedure TAndroidModule1.jAsyncTask1ProgressUpdate(Sender: TObject; progress: integer; out progressUpdate: integer);

These two functions (DoTask and jAsyncTask1ProgressUpdate) run simultaneously in parallel.
These two functions have different times (of processing calculations), and one of them completes calculations earlier than the other.
In case when DoTask takes longer time than jAsyncTask1ProgressUpdate, then AppAsyncTaskDemo1 runs ok.
However if DoTask finishes faster than jAsyncTask1ProgressUpdate, then AppAsyncTaskDemo1 crashes.
As for example, when jAsyncTask1ProgressUpdate updates some GUI component (for example the jProgressBar1), it take quite a long time, and in case if DoTask contains simple short calculations, DoTask finishes faster than it takes to update jProgressBar1, and the app crashes.
As a workaround solution I use the following – I have added separate jTimer which run in separate thread and jTimer updates jProgressBar1.
In order to avoid crash do not update jProgressBar1 in jAsyncTask1ProgressUpdate, because this will lead to crash in case when DoTask finishes faster that jAsyncTask1ProgressUpdate.
« Last Edit: July 23, 2022, 07:58:10 pm by neuro »

 

TinyPortal © 2005-2018