In the following example if I declare an AsyncTask
android studio gives a warning so that I should define it static. According to the this great explanation we define it as a static class to make it possible for virtual machine to garbage collect the service.
But it appears that thread does not need to be static. Why is that? Is it just android studio that doesn't give a warning or thread behaves in a totally different way?
public class MyTrackingService extends Service {
class TrackingThread extends Thread {
private final Context cotext;
TrackingThread(Context context){
this.cotext = context;
}
@Override
public void run() {
super.run();
}
}
class TrackingTask extends AsyncTask<Void, Void, Void> {
private final Context context;
TrackingTask(Context context){
this.context = context;
}
@Override
protected Void doInBackground(Void... voids) {
return null;
}
}
}