Hey, first time using an API, I was wondering if anyone could give me tips/suggestions based on my code. Thanks.
class results extends AsyncTask{
protected void onPreExecute(){
listViewMovies.setText("");
}
protected String doInBackground(Void... urls){
String results = getIntent().getStringExtra("Time String");//Criteria 1
String results2 = getIntent().getStringExtra("Genre String");//Criteria 2
String results3 = getIntent().getStringExtra("Decade String");//Criteria 3
try {
URL url = new URL(https://api.themoviedb.org/3/movie/550?api_key=11111111notmyapikeyappend_to_response=results,results2,results3)
HttpsURLConnection urlconnection = (HttpsURLConnection) url.openConnection();
try{
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null){
stringBuilder.append(line).append("\n");
}
bufferedReader.close();
return stringBuilder.toString();
}
finally {
urlconnection.disconnect();
}
}
catch (Exception e){
}
protected void onPostExecute(String Result){
if(Result == null){
Result = "Error";
}
listViewMovies.setText(Result);
};
}
}
}
Não consegue encontrar um certo filme ou série? Inicie sessão e adicione-o.
Deseja classificar ou adicionar este item a uma lista?
Ainda não é um membro?
Resposta de Kevin Deery
em 15 dezembro 2015 às 6:37 AM
Hi pfoley3090,
I would advise using Newtonsoft , you can get this from Nuget
Its very handy for reading the response and putting it directly into an object, once it in an object its very easy to movie the values around and place to specific controls within your view :)