Android Concurrent Executor Interface

Submitted by Dickens A S on Sat, 03/26/2022 - 14:33

This article demonstrates how to use Core Java in android for concurrent Executor,

Question: Why we should use Core Java Executor? why not AsyncTask?

Answer: The reason is android based SDK announced AsyncTask is Deprecated

Question: So simple core java Runnable is good?

Answer: Not really, But in combination with java.util.concurrent.Executor Runnable is good

Question: Is this told by android SDK documentation

Answer: Yes, As shown below

https://developer.android.com/reference/android/os/AsyncTask

The below source code provides one approach to achieve the same

Source Code

The basic idea is

ex = Executors.newSingleThreadExecutor();
ex.execute(th);

Where the th is your thread class object, how you create the thread class is up to

Now how to access the UI ?

The basic idea of accessing the UI is runOnUiThread

runOnUiThread(new Runnable() {
    @Override
    public void run() {
       //Access UI
    }
});

Article Ends here :) 

Concurrent
Executor
Interface
Java
Android

Add new comment