Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can I use in core Java as an alternative of Async Task in Android

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?

like image 258
Rockcollins Avatar asked Feb 24 '12 11:02

Rockcollins


People also ask

What is the alternative for async task in Android Java?

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.

What can I use instead of async task?

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.

What is the difference between async task and thread?

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.


1 Answers

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.

like image 190
Dhaval Avatar answered Sep 23 '22 15:09

Dhaval