My main application does this: It retrievs data from the internet and has 3 button, when OnClicked, i am going to 3 other screens. because the data loading may be a little slow, I want to use an async Task. This is my sample code for asynctask.
class LoginProgressTask extends AsyncTask {
@Override
protected Boolean doInBackground(String... params) {
try {
Thread.sleep(4000); // Do your real work here
} catch (InterruptedException e) {
e.printStackTrace();
}
return Boolean.TRUE; // Return your real result here
}
@Override
protected void onPreExecute() {
showDialog(AUTHORIZING_DIALOG);
}
@Override
protected void onPostExecute(Boolean result) {
// result is the value returned from doInBackground
removeDialog(AUTHORIZING_DIALOG);
}
}
and this is my sample of my main activity:
public class MainScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainTheme();
}
public void MainTheme(){
retrieve_data(); //function for getting the data
... action with the buttons, onClicks Listener
}
}
My question is how can I mix those codes in One activity to make it work, becuase I haven’t understood AsyncTask. Or what I should return in the doInBackground?
I learned it from >> AsynTask link. may be it will helpful to you too, first read the whole example then start applying it on your code.