I am learning Android via a book and would just like to confirm something.
When using AsyncTask according to the book it goes something like this:
main class
{
new AddStringTask().execute();
}
class AddStringTask extends AsyncTask<Void, String, Void> {
@Override
protected Void doInBackground(Void... unused) {
// Do something
SystemClock.sleep(333);
return(something);
}
@Override
protected void onProgressUpdate(String... item) {
// update something
}
}
which creates one background thread to do some stuff.
So if I want more threads, for example firing at different times (300, 500, 1000 milliseconds) then I need
to make even more sub classes… true?
Or is there some way to do multiple threads firing at different times using just this one subclass?
Thanks!
Not true.
You can just execute the same
AsyncTaskagain by creating anew AddStringTask()instance. This works since it’ll be a new instance which differs from the other ones and each instance has its own thread. They are not interdependent.However, the timer mechanism is something you have to implement yourself.