I have created an app in android. Now I want to create a web version using PlayN. What I want is to replace all the android specific code to normal java code. In android version I use Async task. What can I use instead of this?
There are many alternatives are available for replacing an AsyncTask, one of the replacements is ExecutorService. Above code snippet is general example of AsyncTask, for replace deprecated Async class, first create one Generic Class which is used to replace AsyncTask.
util. concurrent or Kotlin concurrency utilities instead. AsyncTask was intended to enable proper and easy use of the UI thread. However, the most common use case was for integrating into UI, and that would cause Context leaks, missed callbacks, or crashes on configuration changes.
Thread can be triggered from any thread, main(UI) or background; but AsyncTask must be triggered from main thread. Also on lower API of Android(not sure, maybe API level < 11), one instance of AsyncTask can be executed only once.
Async Task is nothing but just a separate thread.You can create your on thread and add the code which you written in doInBackground(Void... params) in the thread's run() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With