Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

may have two AsyncTask classes in ONE java file(=Activity file)?

 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may have two AsyncTask classes in ONE java file(=Activity file)?

private class SaveSharedPreferences extends AsyncTask<String, Object, Object>
{

}

private class LoadSharedPreferences extends AsyncTask<Object, Object, SharedPreferences>
{

}
 
Przemek Boryka
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

In my opinion, You can have as many asynctask as you want, its becous of one fact:
AsyncTask allows you to perform asynchronous work on your user interface. It performs the blocking operations in a worker thread and then publishes the results on the UI thread, without requiring you to handle threads and/or handlers yourself.

The second fact is :
When first introduced, AsyncTasks were executed serially on a single background thread. Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting with HONEYCOMB, tasks are executed on a single thread to avoid common application errors caused by parallel execution. ;)

I have a little experience with AsyncTask, so my answer for your question can be wrong.

Bye Sorry for my english !
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!