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);
};
}
}
}
¿No encuentras una película o serie? Inicia sesión para crearla:
¿Quieres puntuar o añadir este elemento a una lista?
¿No eres miembro?
Contestado por Kevin Deery
el 15 de diciembre de 2015 a las 06:37
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 :)