In my android app I am performing some operations in the doInBackground
by extending AsyncTask<Void, Void, Void>
class. (I have no use in performing any UI in this class)
- Is this proper use of AsyncTask ?
- If so can I extend AsyncTask instead ?
- What is the difference between extending
AsyncTask
andAsyncTask<Void, Void, Void>
Code example:
public class MessagePooling extends AsyncTask<Void, Void, Void>
{
@Override
protected Void doInBackground(Void... params)
{
while (!isCancelled())
{
//Getting data from server
SystemClock.sleep(1000);
}
return null;
}
}
Or:
public class MessagePooling extends AsyncTask
{
@Override
protected Object doInBackground(Object... params)
{
while (!isCancelled())
{
//Getting data from server
SystemClock.sleep(1000);
}
return null;
}
}
Thanks
See Question&Answers more detail:os