is it in general better to create AsyncTask as private class within an Activitiy, or rather separate them in an own class?
public class MyActivity extends Activity {
private class DownloadPage extends AsyncTask {
}
}
is it in general better to create AsyncTask as private class within an Activitiy, or rather separate them in an own class?
public class MyActivity extends Activity {
private class DownloadPage extends AsyncTask {
}
}
AsyncTask inside Activity is more suitable after completing backgroud task you can change view easily.
In seperate class you need to pass
context
and its result comes in seperate class and then you have to get result from seperate class.But seperate class is very useful sometimes when we need more asyncTask in application , and if you have large code in your activity so its better to use seperate class.
So AsyncTask is suitable inside Activity to interact with view...and seperate class is also suitable when we need more asynctask in application.
So its totally depends on requirements...
A private class within the
Activity
has the access to all private members, includingcontext
, which greatly helps not only to do the job, but to showProgressDialog
as well.