I have a basic question about Async task. I'm a beginner in Android programming, sorry for this question.
I'm going to open a socket in doinbackground.
doInBackground(... ) {
Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;
try {
socket = new Socket(192.168.0.1, 2000);
dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataInputStream = new DataInputStream(socket.getInputStream());
}}
What happens to a socket when AsyncTask has finished? (As soon as doInBackground and OnPostExecute has passed.)
Is the Socket still available? Or will it removed by the Garbage Collector?
Next question, but actually the same background.
What happens to an instance of a class which I Instantiate in doInBackground after AsyncTask has finished? (As soon as doInBackground and OnPostExecute has passed.)
doInBackground(... ) {
IPConnection ipcon = new IPConnection();
}
---------------------------------------------------------------------
Edit:
How can I create a reference from a object in Asynctask to the MainActivity?
Edit2:
Is that a reference to the main thread? Would the objects not be removed by the Garbage Collector in that Code Example?
public class ClientActivity extends Activity {
private IPConnection ipcon;
private Socket Testsocket;
public class IPConnection extends AsyncTask<String, String, IPConnection> {
@Override
protected IPConnection doInBackground(String... message) {
ipcon = new IPConnection();
ipcon.run();
return null;
}
}
}
Thank you in advance.