0
0

public class MainActivity extends AppCompatActivity {

private ImageView imageViewStar;
private Button button0;
private Button button1;
private Button button2;
private Button button3;
private String urlImage = "https://www.imdb.com/list/ls050274118/";
private ArrayList<String> names;
private ArrayList<String> urls;
String res;
private TaskContent taskContent;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageViewStar = findViewById(R.id.imageViewStar);
button0 = findViewById(R.id.button0);
button1 = findViewById(R.id.button1);
button2 = findViewById(R.id.button2);
button3 = findViewById(R.id.button3);
taskContent = new TaskContent();
newGetContentTask();
getContent();
}

private void getContent(){

String content = TaskContent.getRes();
Log.i("MyResult", content);


}

public void newGetContentTask(){
final Handler handler = new Handler();
Thread contenThread = new Thread(new Runnable() {
@Override
public void run() {

URL url = null;
HttpURLConnection urlConnection = null;
StringBuilder result = new StringBuilder();

try {
url = new URL(urlImage);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);
String line = reader.readLine();

while (line != null){
result.append(line);
line = reader.readLine();
}
taskContent.setRes(result.toString());

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (urlConnection != null){
urlConnection.disconnect();
}
}

}
});
}

}  Как альтернатива на АсинкТаск использовал но ошибки? 


Батыржан Жумаш
4 years ago






Еще нет ответов