Forum > Android

jAsyncTask bug

(1/1)

Segator:
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.

Segator:
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?

Segator:
Or how i can do a method thread safe?

neuro:
I have tracked down the conditions when jAsyncTask crashes.

https://github.com/jmpessoa/lazandroidmodulewizard/tree/master/demos/GUI/AppAsyncTaskDemo1

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function  TAndroidModule1.DoTask(Progress: integer): boolean;begin  Result:= True; //doing task ...  if Progress < 100 then  begin    Sleep(100 - Progress); //processing task...  end  else    Result:= False; //done !!end;  procedure TAndroidModule1.jAsyncTask1ProgressUpdate(Sender: TObject; progress: integer; out progressUpdate: integer);begin    if progress <= jProgressBar1.Max then   begin      jProgressBar1.Progress:= progress;     // jDialogProgress1.Msg:= 'Lamw: Please, wait... ['+IntToStr(progress)+']';      progressUpdate:= progress + 1; //out param !   end   else   begin     jProgressBar1.Progress:= 0;     //jDialogProgress1.Msg:= 'Lamw: Please, wait...';     progressUpdate:= 0;  //out param !   end; 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.

Navigation

[0] Message Index

Go to full version