public void fetchConfigIfNeeded() { final long configRefreshInterval = 60 * 60; // 1 hour if (config == null || System.currentTimeMillis() - configLastFetchedTime > configRefreshInterval) { // Set the config to current, just to load the cache config = ParseConfig.getCurrentConfig(); // Set the current time, to flag that the operation started and prevent double fetch ParseConfig.getInBackground(new ConfigCallback() { @Override public void done(ParseConfig parseConfig, ParseException e) { if (e == null) { // Yay, retrieved successfully config = parseConfig; configLastFetchedTime = System.currentTimeMillis(); } else { // Fetch failed, reset the time configLastFetchedTime = 0; } } }); } }
public static void refreshConfig() { long currentTime = System.currentTimeMillis(); if (currentTime - lastFetchedTime > configRefreshInterval) { lastFetchedTime = currentTime; ParseConfig.getInBackground(new ConfigCallback() { @Override public void done(ParseConfig config, ParseException e) { if (e == null) { Log.d(TAG, "Fetched config from server."); } else { Log.e(TAG, "Failed to fetch config from server. Using Cached Config."); } cachedConfig = ParseConfig.getCurrentConfig(); Log.d(TAG,"Config is "+cachedConfig.toString()); } }); } }
@Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); Parse.initialize(this, Constants.getConstant(this, R.string.PARSE_APP_ID), Constants.getConstant(this, R.string.PARSE_CLIENT_KEY)); Fabric.with(this, new Crashlytics()); Crashlytics.getInstance().setDebugMode(false); Crashlytics.log(Log.INFO, StarterApplication.class.getName(), "Starting Application - " + System.currentTimeMillis()); NewsCatFileUtil.getInstance(this); UserPrefUtil.getInstance(this); ParseConfig.getInBackground(new ConfigCallback() { @Override public void done(ParseConfig config, ParseException e) { ConfigService.getInstance(); ConfigService.getInstance().setInstance(StarterApplication.this); } }); }