public void newMessage(IrcMessage msg) {
    if ((!preferences.isSpamFilterEnabled()
        || new Date().getTime()
            > IrcNotificationManager.getInstance().getLastSoundDate() + 60000L)) {
      Uri sound = preferences.getNotificationSound();
      if (sound != null) {
        MediaPlayer mp = MediaPlayer.create(this, sound);
        if (mp != null) {
          mp.start();
        }
      }

      if (preferences.isVibrationEnabled()) {
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        if (v != null) {
          v.vibrate(500);
        }
      }

      IrcNotificationManager.getInstance().setLastSoundDate(new Date().getTime());
    }

    if (preferences.isFeedViewDefault()) {
      channelToView = FEED;
    } else {
      channelToView = msg.getLogicalChannel();
    }
    startMainApp(false);
  }
  @Override
  protected void onNewIntent(Intent intent) {
    String intentChannelToView = intent.getStringExtra("Channel");
    if (intentChannelToView != null && !preferences.isFeedViewDefault())
      channelToView = intentChannelToView;

    IrcNotificationManager.getInstance().mainActivityOpened(this);
    startMainApp(false);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Startup");
    super.onCreate(savedInstanceState);

    preferences = new Preferences(this);

    int versionCode = 0;
    try {
      versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
      e.printStackTrace();
    }

    if (preferences.isThemeDisabled()) {
      setTheme(R.style.Theme_LameIrssiTheme);
    }

    MessageToServer.setVersion(versionCode);
    Preferences.setVersion(versionCode);

    // do initial settings
    if (preferences.getAccountName() == null
        || preferences.getGcmRegistrationId() == null
        || preferences.getGcmRegistrationIdVersion() != versionCode
        || (LicenseHelper.isPlusVersion(this) && preferences.getLicenseCount() == 0)) {
      Log.d(TAG, "Asking for initial settings");
      Intent i = new Intent(this, InitialSettingsActivity.class);
      startActivity(i);
      finish();
      return;
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setIndeterminateProgressBarVisibility(false);

    Intent i = getIntent();
    if (i != null) {
      String intentChannelToView = i.getStringExtra("Channel");
      if (intentChannelToView != null && !preferences.isFeedViewDefault())
        channelToView = intentChannelToView;
    }

    boolean b = false;
    if (savedInstanceState != null) {
      b = savedInstanceState.getBoolean("rotated", false);
      channelToView = savedInstanceState.getString("channelToView");
    }

    IrcNotificationManager.getInstance().mainActivityOpened(this);
    startMainApp(b);
  }
  @Override
  protected void onResume() {
    super.onResume();
    instance = this;

    boolean hadMessages = IrcNotificationManager.getInstance().mainActivityOpened(this);

    if (hadMessages || needsRefresh) {
      Log.v(TAG, "onResume needs refreshing");
      needsRefresh = false;
      restart();
    }
  }