I have a very wierd problem. I have some data which I show in a Dialog. If I close the App and reopen it again my ArrayList always adds the original data again (First 5 entries -> close & reopen -> 10 entries -> close & reopen -> 15 entries etc.).
This is how I parse my data into the ArrayList (This only happens once in my TabHost):
JSONArray jPDFs = json.getJSONArray("pdfs");
for (int i = 0; i < jPDFs.length(); i++) {
JSONObject c3 = jPDFs.getJSONObject(i);
String pdf_title = c3.getString("title");
String pdf_url = c3.getString("url");
pdfListTitle.add(pdf_title);
pdfListTitle2.add(pdf_title);
pdfListURL.add(pdf_url);
}
And here is my Code where I show the dialog with the parsed data:
public void showDialog() {
items = null; // have tried with and without...
builder = null; // have tried with and without...
builder = new AlertDialog.Builder(this);
Log.e(TabHost.LOG_TAG, "pdfListTitle=" + TabHost.pdfListTitle.size()); // this always hops from 5 -> 10 -> 15 on every reopen (without killing the app with a taskkiller...)
items = TabHost.pdfListTitle.toArray(new CharSequence[TabHost.pdfListTitle.size()]);
builder.setTitle(R.string.choose_document);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
WebView wv = (WebView) findViewById(R.id.webviewpdf);
wv.setWebViewClient(new WebViewClient());
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl("http://docs.google.com/gview?embedded=true&url="
+ TabHost.pdfListURL.get(item));
}
});
AlertDialog alert = builder.create();
alert.show();
}
Thanks alot in advance for your help!
I think you have taken pdfListTitle as static in TabHost, this may be problem
pdfListTitle should initialize every time when your activity call
for example you can write this code in
onCreate()method like this