0

I have a problem, when the device is online, i can read the news to my website, i parsing use library jsoup, but when the device is offline, the pages that were read will be empty, My question is how when offline i can still read the news already read, whether it is stored in the cache, and if stored how do i get it? My code below is the data from my website i put in the variable DATA. Thanks.

public static String DATA;

private void setData() {
        DATA = "";
        final String URI = ""http://megapolitan.kompas.com/read/2013/01/02/10533531/BMW.Rasyid.Rajasa.Diselimuti.Plastik.Abuabu"";
        new Thread() {
            public void run() {
                try {
                    DATA = new LoadNews().execute(URI).get();
                } catch (Exception e) {
                }
            }
        }.start();
}

private class LoadNews extends AsyncTask<String, Integer, String> {
    private String itemContent;

    protected void onPreExecute() {
        super.onPreExecute();
    }

    protected String doInBackground(String... params) {
        String url = params[0];
        Document doc;
        try {
            doc = Jsoup.connect(url).get();
            Elements element = doc.select("div.isi_berita2011 pt_5");
            itemContent = element.toString();
            return itemContent;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    protected void onPostExecute(String result) {
        dismissProgressDialog();
        super.onPostExecute(result);
    }

}
SubbaReddy PolamReddy
  • 2,083
  • 2
  • 17
  • 23
Loren Ramly
  • 1,091
  • 4
  • 13
  • 21

1 Answers1

0

Put your DATA in a cache. Use your URI as the key. Take a look at Android Objects Cache

Memory cache : http://developer.android.com/reference/android/util/LruCache.html

Disk cache : https://github.com/JakeWharton/DiskLruCache

Community
  • 1
  • 1
Akos Cz
  • 12,711
  • 1
  • 37
  • 32