I got a bit of a Problem with my App, i use a .txt File for getting the right URL's to Display my Pictures that the App should show. Everything works fine. But if i change the Content of the Remote .txt File the App keeps loading the same Pictures again. Here is the code for getting the Pics from remote.
private ArrayList<String> getPictures(){
fileList.clear();
try {
URL url = new URL("http://server.com/test.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(
url.openStream()));
String str;
while ((str = in.readLine()) != null) {
fileList.add(str);
}
in.close();
} catch (MalformedURLException te) {
finish();
} catch (IOException tt) {
finish();
}
return fileList;
}
So i don't have a clue why it isn't getting the new content for i clear the ArrayList each time the method is called!
I hope someone has a Solution for this Problem, it's pretty anoying.
/edit: forgot to post the Method containing the Adapter, so here it is:
private String getAnImageUrl() {
getPictures();
ArrayAdapter<String> arrAdapt = new ArrayAdapter<String>(this, R.layout.main, fileList);
arrAdapt.setNotifyOnChange(true);
i++;
if (i >= arrAdapt.getCount()) {
i = 0;
}
return test = arrAdapt.getItem(i).toString();
}
Yeah, I experienced this with my own app downloading some JSON. The easiest way to fix it is to add a random parameter to your URL request like so:
String urlString = "http://server.com/test.txt?" + System.currentTimeMillis();
URL url = new URL(urlString);
Which will add the current system time to your url as a parameter, which will bypass any cached version of the page