@Override
  protected void onResume() {
    super.onResume();

    refreshPeersFragment();

    initializeAppia();
    initializeOffercast();

    if (ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_GUI_TOS_ACCEPTED)) {
      if (ConfigurationManager.instance()
          .getBoolean(Constants.PREF_KEY_GUI_INITIAL_SETTINGS_COMPLETE)) {
        mainResume();
      } else {
        controller.startWizardActivity();
      }
    } else {
      trackDialog(
          TOS.showEula(
              this,
              new OnTOSAcceptListener() {
                public void onAccept() {
                  controller.startWizardActivity();
                }
              }));
    }

    checkLastSeenVersion();
  }
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   if (outState != null) {
     super.onSaveInstanceState(outState);
     saveLastFragment(outState);
     saveFragmentsStack(outState);
   }
 }
  @Override
  protected void onPause() {
    super.onPause();

    search.dismissDialogs();
    library.dismissDialogs();
    peers.dismissDialogs();
  }
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    saveLastFragment(outState);
    saveFragmentsStack(outState);

    outState.putString(DUR_TOKEN_KEY, durToken);
    outState.putBoolean(APPIA_STARTED_KEY, appiaStarted);
  }
  @Override
  protected void onDestroy() {
    super.onDestroy();

    // avoid memory leaks when the device is tilted and the menu gets recreated.
    SoftwareUpdater.instance().removeConfigurationUpdateListener(this);

    if (playerItem != null) {
      playerItem.unbindDrawables();
    }
  }
  @Override
  protected void onPause() {
    super.onPause();

    if (mainBroadcastReceiver != null) {
      try {
        unregisterReceiver(mainBroadcastReceiver);
      } catch (Throwable t) {
        // oh well (the api doesn't provide a way to know if it's been registered before,
        // seems like overkill keeping track of these ourselves.)
      }
    }
  }
  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (playerSubscription != null) {
      playerSubscription.unsubscribe();
    }

    // avoid memory leaks when the device is tilted and the menu gets recreated.
    SoftwareUpdater.instance().removeConfigurationUpdateListener(this);

    if (playerItem != null) {
      playerItem.unbindDrawables();
    }

    if (mToken != null) {
      MusicUtils.unbindFromService(mToken);
      mToken = null;
    }
  }
  @Override
  protected void onResume() {
    super.onResume();

    refreshPlayerItem();

    if (ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_GUI_TOS_ACCEPTED)) {
      if (ConfigurationManager.instance()
          .getBoolean(Constants.PREF_KEY_GUI_INITIAL_SETTINGS_COMPLETE)) {
        mainResume();
        Offers.initAdNetworks(this);
      } else {
        controller.startWizardActivity();
      }
    } else {
      TermsUseDialog dlg = new TermsUseDialog();
      dlg.show(getFragmentManager());
    }

    checkLastSeenVersion();
    registerMainBroadcastReceiver();
  }
 @Override
 protected void onPostCreate(Bundle savedInstanceState) {
   super.onPostCreate(savedInstanceState);
   drawerToggle.syncState();
 }
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   drawerToggle.onConfigurationChanged(newConfig);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mToken = MusicUtils.bindToService(this, this);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    drawerLayout = findView(R.id.drawer_layout);
    drawerLayout.setDrawerListener(
        new SimpleDrawerListener() {
          @Override
          public void onDrawerStateChanged(int newState) {
            refreshPlayerItem();
            syncSlideMenu();
          }

          @Override
          public void onDrawerSlide(View drawerView, float slideOffset) {
            if (slideOffset > 0) {
              buttonMainMenu.setImageResource(R.drawable.main_menu_button_icon_selected);
            } else {
              buttonMainMenu.setImageResource(R.drawable.main_menu_button_icon);
            }
          }

          @Override
          public void onDrawerOpened(View drawerView) {
            buttonMainMenu.setImageResource(R.drawable.main_menu_button_icon_selected);
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            buttonMainMenu.setImageResource(R.drawable.main_menu_button_icon);
          }
        });

    leftDrawer = findView(R.id.activity_main_left_drawer);
    listMenu = findView(R.id.left_drawer);

    playerItem = findView(R.id.slidemenu_player_menuitem);
    playerItem.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            controller.launchPlayerActivity();
          }
        });

    buttonMainMenu = findView(R.id.activity_main_button_menu);
    buttonMainMenu.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            toggleDrawer();
          }
        });

    setupFragments();

    setupInitialFragment(savedInstanceState);

    setupMenuItems();

    if (savedInstanceState != null) {
      durToken = savedInstanceState.getString(DUR_TOKEN_KEY);
      appiaStarted = savedInstanceState.getBoolean(APPIA_STARTED_KEY);
    }

    addRefreshable((Refreshable) findView(R.id.activity_main_player_notifier));

    onNewIntent(getIntent());

    SoftwareUpdater.instance().addConfigurationUpdateListener(this);
  }