public void clearAllCache(Context ctx) {
   BreadcrumbsTracks.initCacheVariables();
   setChanged();
   clearPersistentCache(ctx);
   notifyObservers();
 }
  /**
   * Read the static breadcrumbs data from private file
   *
   * @param ctx
   * @return is refresh is needed
   */
  @SuppressWarnings("unchecked")
  public boolean readCache(Context ctx) {
    FileInputStream fis = null;
    ObjectInputStream ois = null;
    Date bundlesPersisted = null, activitiesPersisted = null;
    Object[] cache;
    synchronized (BREADCRUMSB_BUNDLES_CACHE_FILE) {
      try {
        fis = ctx.openFileInput(BREADCRUMSB_BUNDLES_CACHE_FILE);
        ois = new ObjectInputStream(fis);

        cache = (Object[]) ois.readObject();
        // new Object[] { CACHE_VERSION, new Date(), sActivitiesWithBundles, sBundlesWithTracks,
        // sBundleMappings, sTrackMappings };
        if (cache[0] instanceof Integer && CACHE_VERSION.equals(cache[0])) {
          bundlesPersisted = (Date) cache[1];
          HashMap<Integer, List<Integer>> bundles = (HashMap<Integer, List<Integer>>) cache[2];
          HashMap<Integer, Map<String, String>> bundlemappings =
              (HashMap<Integer, Map<String, String>>) cache[3];
          HashMap<Integer, Map<String, String>> trackmappings =
              (HashMap<Integer, Map<String, String>>) cache[4];
          sBundlesWithTracks = bundles != null ? bundles : sBundlesWithTracks;
          sBundleMappings = bundlemappings != null ? bundlemappings : sBundleMappings;
          sTrackMappings = trackmappings != null ? trackmappings : sTrackMappings;
        } else {
          clearPersistentCache(ctx);
        }

        fis = ctx.openFileInput(BREADCRUMSB_ACTIVITY_CACHE_FILE);
        ois = new ObjectInputStream(fis);
        cache = (Object[]) ois.readObject();
        // new Object[] { CACHE_VERSION, new Date(), sActivityMappings };
        if (cache[0] instanceof Integer && CACHE_VERSION.equals(cache[0])) {
          activitiesPersisted = (Date) cache[1];
          HashMap<Integer, Map<String, String>> activitymappings =
              (HashMap<Integer, Map<String, String>>) cache[2];
          sActivityMappings = activitymappings != null ? activitymappings : sActivityMappings;
        } else {
          clearPersistentCache(ctx);
        }
      } catch (OptionalDataException e) {
        clearPersistentCache(ctx);
        Log.w(TAG, "Unable to read persisted breadcrumbs cache", e);
      } catch (ClassNotFoundException e) {
        clearPersistentCache(ctx);
        Log.w(TAG, "Unable to read persisted breadcrumbs cache", e);
      } catch (IOException e) {
        clearPersistentCache(ctx);
        Log.w(TAG, "Unable to read persisted breadcrumbs cache", e);
      } catch (ClassCastException e) {
        clearPersistentCache(ctx);
        Log.w(TAG, "Unable to read persisted breadcrumbs cache", e);
      } catch (ArrayIndexOutOfBoundsException e) {
        clearPersistentCache(ctx);
        Log.w(TAG, "Unable to read persisted breadcrumbs cache", e);
      } finally {
        if (fis != null) {
          try {
            fis.close();
          } catch (IOException e) {
            Log.w(TAG, "Error closing file stream after reading cache", e);
          }
        }
        if (ois != null) {
          try {
            ois.close();
          } catch (IOException e) {
            Log.w(TAG, "Error closing object stream after reading cache", e);
          }
        }
      }
    }
    setChanged();
    notifyObservers();

    boolean refreshNeeded = false;
    refreshNeeded = refreshNeeded || bundlesPersisted == null || activitiesPersisted == null;
    refreshNeeded =
        refreshNeeded
            || (activitiesPersisted.getTime() < new Date().getTime() - CACHE_TIMEOUT * 10);
    refreshNeeded =
        refreshNeeded || (bundlesPersisted.getTime() < new Date().getTime() - CACHE_TIMEOUT);

    return refreshNeeded;
  }