private void initWallet() {

    new LinuxSecureRandom(); // init proper random number generator
    initLogging();

    Threading.throwOnLockCycles();

    log.info(
        "=== starting app using configuration: {}, {}",
        Constants.TEST ? "test" : "prod",
        Constants.NETWORK_PARAMETERS.getId());

    super.onCreate();

    CrashReporter.init(getCacheDir());

    Threading.uncaughtExceptionHandler =
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(final Thread thread, final Throwable throwable) {
            log.info("peercoinj uncaught exception", throwable);
            CrashReporter.saveBackgroundTrace(throwable, packageInfo);
          }
        };

    initMnemonicCode();

    config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this));
    walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);

    // Rename old wallets

    final File oldWalletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF_OLD);
    if (oldWalletFile.exists()) oldWalletFile.renameTo(walletFile);

    loadWalletFromProtobuf();

    config.updateLastVersionCode(packageInfo.versionCode);

    afterLoadWallet();
    cleanupFiles();

    synchronized (this) {
      isLoaded = true;

      for (Runnable callback : loadedCallbacks) callback.run();
    }
  }