5

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?

Rockcollins
  • 418
  • 5
  • 15

3 Answers3

3

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.

Dhaval
  • 553
  • 3
  • 9
  • Dhavai what about onPreExecute and onPostExecute ? And I need to update UI too. – Rockcollins Feb 24 '12 at 12:15
  • This thing is done by your main thread which call childthread.start() method. – Dhaval Feb 24 '12 at 12:23
  • 1
    and see the Thread.Join() function. By this function u can block your main thread till the childthread is complete its work. And after join() write your onPostExecute () code. – Dhaval Feb 24 '12 at 12:26
1

Try SwingWorker

Other refefernces:

  1. How do I use SwingWorker in Java?
  2. Java GUI threads - SwingWorker
  3. What is the rationale of SwingWorker?
Community
  • 1
  • 1
Azodious
  • 13,752
  • 1
  • 36
  • 71
1

You can download the Android Source and copy the AsyncTask source to your project. Its does not have dependency of Android.

You can find AsyncTask.java here

Vivek Khandelwal
  • 7,829
  • 3
  • 25
  • 40