[FREE] Unlock Seamless Background Operations: Introducing the Ultimate Asynchronous Task Extension

Enhanced Asynchronous Task Extension

An extension for MIT App Inventor 2.
Enhanced extension for interacting with App Inventor blocks, using ExecutorService for asynchronous tasks with improved lifecycle management, thread safety, and monitoring capabilities.

:memo: Specifications


:package: Package: com.bosonshiggs.enhancedasynchronoustask
:floppy_disk: Size: 65,32 KB
:gear: Version: 4.0
:mobile_phone: Minimum API Level: 14
:date: Updated On: 2026-02-23
:laptop: Built & documented using: FAST v5.5.0
:counterclockwise_arrows_button: Recompiled with: FAST Compiler - Optimized for better performance and compatibility

:books: Overview

This extension provides advanced asynchronous task management capabilities for MIT App Inventor 2 applications. It uses Java’s ExecutorService to handle background operations efficiently, with features like task scheduling, progress tracking, timeout management, and state persistence. The extension has been recompiled using the FAST compiler for optimized performance and better integration with App Inventor projects.

Events:

EnhancedAsynchronousTask has total 10 events.

1. OnTimeEvent

Description: Event triggered at the specified time when using ScheduleEventAtTime().
Usage: Connect this event block to execute code when the scheduled time is reached.

2. AsyncTaskWithDelayCompleted

Description: Event fired when an asynchronous task with delay is completed.
Usage: Triggered after StartAsyncTaskWithDelay() finishes execution. Use the taskId parameter to identify which task completed.

Parameter Type Description
taskId text The unique identifier of the completed task

3. RepeatingTaskTriggered

Description: Event fired each time a repeating task interval is reached.
Usage: This event fires repeatedly at the interval specified in StartRepeatingTask(). Handle periodic operations here.

Parameter Type Description
taskId text The identifier of the repeating task being triggered

4. AsyncTaskProgressUpdated

Description: Event fired to update on the progress of a progressive task.
Usage: Used with StartProgressiveTask() to receive progress updates. Great for UI progress bars.

Parameter Type Description
taskId text The task reporting progress
progress number Progress percentage (0-100)

5. AsyncTaskResultReceived

Description: Event fired with the result of a completed asynchronous task.
Usage: Receives the final result from tasks like StartProgressiveTask() or StartTaskWithTimeout().

Parameter Type Description
taskId text The task that produced the result
result any The result data (can be text, number, or list)

6. AsyncTaskErrorOccurred

Description: Event fired when an error occurs during task execution.
Usage: Handle task failures and display error messages to users.

Parameter Type Description
taskId text The task where the error occurred
errorMessage text Description of what went wrong

7. AllTasksCancelled

Description: Event triggered when all tasks have been successfully cancelled.
Usage: Confirmation event after calling CancelAllTasksAsync() when all tasks are properly terminated.

8. TasksOperationComplete

Description: Event triggered when any task operation completes successfully.
Usage: General-purpose completion event for various operations.

Parameter Type Description
message text Success message describing the completed operation

9. DetailedErrorOccurred

Description: Event triggered with detailed error information including category.
Usage: Advanced error handling with error categorization for debugging.

Parameter Type Description
taskId text The task where the error occurred
errorMessage text Detailed error description
category text Error category (TIMEOUT, INTERRUPTION, EXECUTION, SCHEDULING, VALIDATION, RESOURCE)

10. TaskStateSaved

Description: Event triggered when task state is successfully saved to a file.
Usage: Confirmation that SaveTaskState() completed successfully.

Parameter Type Description
filename text Name of the file where state was saved

Methods:

EnhancedAsynchronousTask has total 13 methods.

1. Cleanup

Description: Gracefully cleans up resources and shuts down the executor. Call this when the extension is no longer needed.
Usage: Always call this in your app’s shutdown sequence or when permanently done with background tasks to prevent memory leaks.

call EnhancedAsynchronousTask1.Cleanup

2. CancelAllTasksAsync

Description: Cancels all scheduled or running tasks asynchronously.
Usage: Use to terminate all background operations at once. Triggers AllTasksCancelled() when done.

call EnhancedAsynchronousTask1.CancelAllTasksAsync

3. CancelAsyncTask

Description: Cancels a specific asynchronous task by its identifier.
Usage: Target a single task for cancellation while leaving others running.

Parameter Type Description
taskId text The unique ID of the task to cancel
call EnhancedAsynchronousTask1.CancelAsyncTask
    taskId: "task_1"

4. StartAsyncTaskWithDelay

Description: Starts a one-time task after a specified delay.
Usage: Perfect for delayed operations like showing notifications after a pause.

Parameter Type Description
delayMillis number Delay in milliseconds before task executes
taskId text Unique identifier for this task
call EnhancedAsynchronousTask1.StartAsyncTaskWithDelay
    delayMillis: 5000
    taskId: "delayed_notification"

5. StartRepeatingTask

Description: Starts a task that repeats at fixed intervals.
Usage: Ideal for periodic updates, polling, or recurring background operations.

Parameter Type Description
intervalMillis number Interval between repetitions in milliseconds
taskId text Unique identifier for this repeating task
call EnhancedAsynchronousTask1.StartRepeatingTask
    intervalMillis: 60000
    taskId: "minute_updater"

6. StartProgressiveTask

Description: Executes a task that reports its progress in steps.
Usage: Great for operations with multiple stages like file processing or data syncing.

Parameter Type Description
taskId text Unique identifier for this task
totalSteps number Total number of steps in the process
call EnhancedAsynchronousTask1.StartProgressiveTask
    taskId: "data_import"
    totalSteps: 10

7. StartTaskWithTimeout

Description: Executes a task with automatic cancellation if it exceeds the timeout.
Usage: Prevent hanging operations by setting a maximum execution time.

Parameter Type Description
taskId text Unique identifier for this task
timeoutSeconds number Maximum execution time in seconds
totalSteps number Total steps for progress reporting
call EnhancedAsynchronousTask1.StartTaskWithTimeout
    taskId: "network_request"
    timeoutSeconds: 30
    totalSteps: 5

8. CheckTaskStatus

Description: Returns the current status of a specific task.
Return type: text - Returns “Not Found”, “Cancelled”, “Completed”, “Running”, or “Error”
Usage: Monitor task state for conditional logic.

Parameter Type Description
taskId text The task ID to check
set status to call EnhancedAsynchronousTask1.CheckTaskStatus
    taskId: "task_1"

9. GetAllTaskIDs

Description: Returns a list containing all active task identifiers.
Return type: list - YailList of task IDs
Usage: Get an overview of all running or scheduled tasks.

set activeTasks to call EnhancedAsynchronousTask1.GetAllTaskIDs

10. GetTaskStatistics

Description: Returns statistics about task execution.
Return type: list - Contains completed, failed, cancelled, active counts, and thread pool size
Usage: Monitor extension performance and task history.

set stats to call EnhancedAsynchronousTask1.GetTaskStatistics

11. RunTasksSequentially

Description: Executes multiple tasks in sequence, one after another.
Usage: Chain dependent operations where each task must complete before the next starts.

Parameter Type Description
taskIds list List of task IDs in execution order
taskSteps list List of step counts for each task
call EnhancedAsynchronousTask1.RunTasksSequentially
    taskIds: create list "task1" "task2" "task3"
    taskSteps: create list 5 3 7

12. ScheduleEventAtTime

Description: Schedules an event at a specific date and time.
Usage: Set up calendar-based notifications or scheduled operations.

Parameter Type Description
year number Year (e.g., 2026)
month number Month (1-12)
day number Day of month (1-31)
hour number Hour (0-23)
minute number Minute (0-59)
second number Second (0-59)
millisecond number Millisecond (0-999)
call EnhancedAsynchronousTask1.ScheduleEventAtTime
    year: 2026
    month: 3
    day: 15
    hour: 14
    minute: 30
    second: 0
    millisecond: 0

13. SaveTaskState

Description: Saves current task states and statistics to a JSON file.
Usage: Persist task information for recovery or debugging purposes.

Parameter Type Description
filename text Name of the file to save (without path)
call EnhancedAsynchronousTask1.SaveTaskState
    filename: "task_backup.json"

Designer Properties:

1. ThreadPoolSize

Description: Sets the number of concurrent threads available for task execution.
Input type: non_negative_integer
Default value: 4
Usage: Increase for more parallel tasks, decrease for resource-constrained devices.

Setters & Getters:

Setter: ThreadPoolSize

Description: Dynamically changes the thread pool size during runtime.
Input type: number
Usage: Adjust performance based on current app needs.

set EnhancedAsynchronousTask1.ThreadPoolSize to 8

Getter: ThreadPoolSize

Description: Returns the current thread pool size.
Return type: number
Usage: Check current concurrency settings.

set currentSize to EnhancedAsynchronousTask1.ThreadPoolSize

:light_bulb: Best Practices

  1. Always use unique task IDs to avoid conflicts
  2. Call Cleanup() when the screen closes or app exits
  3. Monitor timeouts for network operations
  4. Use progressive tasks for long operations to keep UI responsive
  5. Save task state periodically for critical operations
  6. Adjust thread pool size based on device capabilities
  7. Handle errors using both error events for robust apps

:rocket: Performance Notes

  • Recompiled with FAST compiler v5.5.0 for optimal performance
  • Thread-safe implementation using ConcurrentHashMap
  • Automatic resource management with proper cleanup
  • Configurable thread pool for different device capabilities
  • JSON state persistence for debugging and recovery

Files


New files (Fast Cli)

Old files

12 Likes

Seems like a Great Extension , what if you add a demo video or Demo blocks how this work

2 Likes

It’s looks like a very helpful extension.

I am also like to see how it will work.
any demo block?

1 Like

Thanks! I will record a video and add an AIA file.

2 Likes

AIA files and demo videos added!

1 Like

Parabéns mais uma vez pelo seu trabalho!
Porém, eu ainda não entendi onde eu poderia aplicar em uma situação real.
Obrigado.

Congratulations once again on your work! However, I still don’t understand where I could apply it in a real situation.

1 Like

The extension can be used when you want to perform more than one task at the same time without blocking the App UI. The extension comes with a bonus method for creating alarms.

The extension allows you to perform more than one task at the same time without having to wait for one task or another to finish.

3 Likes

Hello,
I don’t really hunderstand how to use it…
You have blocks to start async task, but how do you define the task to start ?
is it a procedure with some blocks ? but then how do you give it the Id ?
could you show some exemples please ?

1 Like

See the example in the AIA file available

Thanks for the extension.

Quick question- Will it still work if the app is sent to the background?

Mohan

You always can use itoo to get extensions working in the background

Taifun

great extension

1 Like

@Passos_0213
i understand how repeated task work , but i do not understand how this works ?

component_method

how to tell extension which task to do ?

mean i want to add items to list async , but how ?

1 Like

I have the same question.

Hi dear,

The extension is used to execute repeated tasks asynchronously.
Inside .AsyncTaskTriggered, you should place the code you want to execute, as shown in the developer’s example.

If you need to run different tasks, I suggest adding a counter that tracks how many times the task has been executed, and based on that counter, perform different operations (still inside .AsyncTaskTriggered).

2 Likes

Can you give a visual example ,
I dont want to run repeated task , i just want to run task asynchronously, any task …

1 Like

check this

I believe they have already tried using this extension, but without success.

If I understood correctly, you want to add random numbers from 21212 to 21212121 to a list.
Since you’re trying to use this extension, I imagine the elements to add are so many that the UI freezes.
To work around this issue, you could also simply use a Clock.

As the developer pointed out, this extension has much more potential

In any case, here is an example of how to add 100 elements to a list with a delay using a repeating task.


Try showing me an example of these tasks you need to execute, because I’m not fully understanding the requirement.

“taskid” is the name of the procedure, which you want to run.