Here is a task initialization code
CoordsAnalizatorTask coordsAnalizatorTask = new CoordsAnalizatorTask(); Next, I run it with parameters
coordsAnalizatorTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, new Double[]{coords_w, coodrs_l, angle}); In essence, AsyncTask.SERIAL_EXECUTOR indicates that tasks will be performed sequentially, which I have no doubt. I found an article where there is an example and it is clearly visible that calls are made sequentially (at the very bottom of the article) i.e. if i send tasks like this
coordsAnalizatorTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, new Double[]{coords_w, coodrs_l, angle}); coordsAnalizatorTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, new Double[]{coords_w, coodrs_l, angle}); Both of them should be transferred to AsyckTask , but they will not be executed in parallel, but in series, which is what I need, but performing such actions gives me an error
12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: FATAL EXCEPTION: main 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: Process: com.example.miroshnichenko.mylineviewexample, PID: 21238 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.miroshnichenko.mylineviewexample/com.example.miroshnichenko.mylineviewexample.MainActivity}: java.lang.IllegalStateException: Cannot execute task: the task is already running. 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:177) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:145) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5942) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: Caused by: java.lang.IllegalStateException: Cannot execute task: the task is already running. 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:576) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.example.miroshnichenko.mylineviewexample.CoordinatesAnalizator.sendCoords(CoordinatesAnalizator.java:63) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.example.miroshnichenko.mylineviewexample.NmeaParser.addNmeaByteArray(NmeaParser.java:62) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.example.miroshnichenko.mylineviewexample.MainActivity.onCreate(MainActivity.java:56) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6289) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:177) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:145) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5942) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 12-01 12:40:41.811 21238-21238/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) As if to say that I cannot use AsyncTask while it is working, which is very strange, since in the example it is clearly written that sequential execution with such a call should be and be without errors.
The essence of the task is such that there is a stream that constantly parses the coordinates and throws them into AsyncTask , then the task should work with them consistently, i.e. handle one task after another, but those on, such a problem arose. Prompt a solution to the problem or suggest an alternative. Thank you in advance!