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);
};
}
}
}
Non riesci a trovare un film o una serie Tv? Accedi per crearlo.
Vuoi valutare o aggiungere quest'elemento a una lista?
Non sei un membro?
Risposta da Kevin Deery
il 15 dicembre, 2015 alle 6:37AM
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 :)