private class DownloadTask extends AsyncTask URL Integer String Overri

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
private class DownloadTask extends AsyncTask<URL, Integer, String> {
@Override
protected String doInBackground(URL... params) {
URL yahoo = null;
try {
yahoo = new URL("http://www.spaces.ru/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));
String inputLine = null;
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
String result = "";
while ((inputLine = in.readLine()) != null) {
result += inputLine;
}
in.close();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NetworkOnMainThreadException e ) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// Дебаг. Уровень: бог.
TextView textView = (TextView) findViewById(R.id.textView22);
textView.setText(result);
}
}