Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:13:31+00:00 2026-05-31T20:13:31+00:00

I want to cache data from a json-webservice in my android app. The first

  • 0

I want to cache data from a json-webservice in my android app. The first time, the application is launched, it should wait until all data was loaded from service. After that initial load the app should check from time to time(some days) if there is new data available. If yes, the locally stored data should be refreshed and loaded the next time the app is started.

Currently I’m trying to solve this by an IntentService and by saving the loaded data in a file – but i isn’t a very clean an beautiful way!

Does anybody know a clean way to do this? A caching-pattern?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:13:32+00:00Added an answer on May 31, 2026 at 8:13 pm

    Here’s a simply way to do this that doesn’t involve a service, threads, alarms, etc. just define a wrapper around your JSON, like,

    class MyJson {
        JSONObject getJson() { ... };
    }
    

    the implementation of getJson() does the following,

    if (cached json file exists) {
      if (json file last modified + 1 day > current time) {
        json = get from network;
        cache json in file;
      } else [
        json = get from file;
      }
    } else {
        json = get from network;
        cache json in file;
    }
    

    in other words, lazy-fetch the fresh json from the network when you need it. this is vastly simpler than periodically updating a cache file by setting alarms and running a service to update the cache …

    from your app, you do the same thing whether it’s the first load or the Nth load of the data. you call getJson(),

    new Thread(new Runnable() {
      public void run() {
        json = getJson();
        // do whatever you need to do after the json is loaded
      }
    }).start();
    

    the only downside is that occasionally, the call to get the JSON will take longer, and consequently you must run it in a thread so as not to ANR the UI … but you should do that anyway, because whether it’s in a file or fetched from the network, you should avoid doing IO in the UI thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to cache custom data in an ASP.NET application. I am putting lots
I want to display from cache for a long time and I want a
I want to send a large amount of cached json data from an import
I am newer for php. I want make php page cache, query data from
I have some status data that I want to cache from a database. Any
It's common to want browsers to cache resources - JavaScript, CSS, images, etc. until
I want to implement a two-pass cache system: The first pass generates a PHP
I do not want my Java SWT application to cache temporary internet files. Currently
I'm working on an iPhone application that downloads data from a web server and
How can I get Fullcalendar to cache events from a JSON feed? I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.