AsyncTaskLoader vs AsyncTask

You can have a look at the compatibility library’s source code to get more info. What a FragmentActivity does is: keep a list of LoaderManager‘s make sure they don’t get destroyed when you flip your phone (or another configuration change occurs) by saving instances using onRetainNonConfigurationInstance() kick the right loader when you call initLoader() in … Read more

Execute AsyncTask several times

AsyncTask instances can only be used one time. Instead, just call your task like new MyAsyncTask().execute(“”); From the AsyncTask API docs: Threading rules There are a few threading rules that must be followed for this class to work properly: The task instance must be created on the UI thread. execute(Params…) must be invoked on the … Read more

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

You should do the transaction in a Handler as follows: @Override protected void onPostExecute(String result) { Log.v(“MyFragmentActivity”, “onFriendAddedAsyncTask/onPostExecute”); new Handler().post(new Runnable() { public void run() { fm = getSupportFragmentManager(); ft = fm.beginTransaction(); ft.remove(dummyFragment); ft.commit(); } }); }

Difference between Service, Async Task & Thread?

Probably you already read the documentation description about them, I won’t repeat them, instead I will try to give answer with my own words, hope they will help you. Service is like an Activity but has no user interface. Probably if you want to fetch the weather for example you won’t create a blank activity … Read more

Asynctask vs Thread in android

For long-running or CPU-intensive tasks, there are basically two ways to do this: Java threads, and Android’s native AsyncTask. Neither one is necessarily better than the other, but knowing when to use each call is essential to leveraging the system’s performance to your benefit. Use AsyncTask for: Simple network operations which do not require downloading … Read more

android asynctask sending callbacks to ui [duplicate]

You can create an interface, pass it to AsyncTask (in constructor), and then call method in onPostExecute() For example: Your interface: public interface OnTaskCompleted{ void onTaskCompleted(); } Your Activity: public class YourActivity implements OnTaskCompleted{ // your Activity } And your AsyncTask: public class YourTask extends AsyncTask<Object,Object,Object>{ //change Object to required type private OnTaskCompleted listener; public … Read more

What arguments are passed into AsyncTask?

Google’s Android Documentation Says that : An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute. AsyncTask’s generic types : The three types used by an asynchronous task are the following: Params, the type of the parameters sent to the task upon … Read more

The AsyncTask API is deprecated in Android 11. What are the alternatives?

You can directly use Executors from java.util.concurrent package. I also searched about it and I found a solution in this Android Async API is Deprecated post. Unfortunately, the post is using Kotlin, but after a little effort I have converted it into Java. So here is the solution. ExecutorService executor = Executors.newSingleThreadExecutor(); Handler handler = … Read more