Reputation: 86847
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 {
}
}
Upvotes: 0
Views: 163
Reputation: 40416
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...
Upvotes: 2
Reputation: 23556
A private class within the Activity
has the access to all private members, including context
, which greatly helps not only to do the job, but to show ProgressDialog
as well.
Upvotes: 1