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);
};
}
}
}
Nemôžeš nájsť film alebo seriál? Prihlás sa a pridaj ho.
Chcete ohodnotiť alebo pridať túto položku do zoznamu?
Nie ste členom?
Odpoveď od Kevin Deery
dňa 15. december, 2015 o 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 :)