コード例 #1
0
ファイル: CacheManager.java プロジェクト: jmsloat/RedReader
  public void pruneTemp() {

    final File externalCacheDir = context.getExternalCacheDir();
    final File internalCacheDir = context.getCacheDir();

    if (externalCacheDir != null) {
      pruneTemp(externalCacheDir);
    }

    if (internalCacheDir != null) {
      pruneTemp(internalCacheDir);
    }
  }
コード例 #2
0
ファイル: RedReader.java プロジェクト: H4rryA/RedReader
  @Override
  public void onCreate() {

    super.onCreate();

    Log.i("RedReader", "Application created.");

    final Thread.UncaughtExceptionHandler androidHandler =
        Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          public void uncaughtException(Thread thread, Throwable t) {

            try {
              t.printStackTrace();

              File dir = Environment.getExternalStorageDirectory();

              if (dir == null) {
                dir = Environment.getDataDirectory();
              }

              final FileOutputStream fos =
                  new FileOutputStream(
                      new File(
                          dir, "redreader_crash_log_" + UUID.randomUUID().toString() + ".txt"));
              final PrintWriter pw = new PrintWriter(fos);
              t.printStackTrace(pw);
              pw.flush();
              pw.close();

            } catch (Throwable t1) {
            }

            androidHandler.uncaughtException(thread, t);
          }
        });

    final CacheManager cm = CacheManager.getInstance(this);

    cm.pruneTemp();

    new Thread() {
      @Override
      public void run() {

        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);

        cm.pruneCache(); // Hope for the best :)
      }
    }.start();

    new Thread() {
      @Override
      public void run() {
        RedditChangeDataIO.getInstance(RedReader.this).runInitialReadInThisThread();
        RedditChangeDataManager.pruneAllUsers();
      }
    }.start();

    Alarms.onBoot(this);

    NewMessageChecker.checkForNewMessages(this);
  }