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);
};
}
}
}
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by Kevin Deery
on December 15, 2015 at 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 :)