I know there are many threads about this topic, but: I have a simple task.
public class MyTask extends AsyncTask<T, U, V> {
...
@Override
protected Void doInBackground(T... params) {
for (int i = 0; i < 60; i++)
{
if (isCancelled()) return null;
publishProgress(i);
Thread.sleep(1000);
}
return null;
}
...
}
This is pretty straightforward, I count til 60 and update a TextView on the UI. Problems arrive when we have to solve configuration changes (like rotate screen) etc, because we have to avoid memory leaks and correctly handle all threads.
Introduced in Android 3.0, loaders come into play. Loaders are now preferred way of handling long term operations in a background thread (we do not have to take that much care about threads). But if I understood it correctly, they are primary for loading some data from somewhere and displaying them in an Activity / Fragment. Like downloading some web content and displaying it in form of a list etc.
EDITED: Now I found some other possibilities how to do some background work, like with an Fragment without the UI (with the RetainInstance = true when the activity recreates) or an Idea of starting it as a service. They could presumably achieve this in a much simpler way.
My question is, as I am new to Android, which way should I go ?