rauza
Regular Member
- Mar 13, 2014
- 409
- 586
So I've just started on Java generic types and I feel like I understand them pretty well. The concept is clear. I've just been recently learning Android Development and I've been taking a look at this piece of code for Files... and I don't understand why the generic type: <String, Integer, String> was used. Can someone help me out?
How is the AsyncTask<String, Integer, String> being used?
What is being passed in?
How is the AsyncTask<String, Integer, String> being used?
What is being passed in?
Code:
other code...
case R.id.bLoad:
new loadSomeStuff().execute(FILENAME);
break;
}
}
public class loadSomeStuff extends AsyncTask[U][B]<String, Integer, String>[/B][/U]{
protected void onPreExecute(String f) {
// example of setting up something
f = "whatever";
}
//override
protected String doInBackground(String... arg0) {
String collected = null;
FileInputStream fis = null;
try {
fis = openFileInput(FILENAME);
byte[] dataArray = new byte[fis.available()];
while (fis.read(dataArray) != -1) {
collected = new String(dataArray);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
return collected;
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
//... means array
protected void onProgressUpdate(Integer...progress){
}
protected void onPostExecute(String result) {
dataResults.setText(result);
}
}
Last edited: