private void switchTo(UUID uuid) {
    Profile p = mProfileManager.getProfile(uuid);
    if (p != null) {
      mProfileManager.setActiveProfile(uuid);

      Toast.makeText(
              this,
              String.format(getResources().getString(R.string.profile_selected), p.getName()),
              Toast.LENGTH_LONG)
          .show();
      NFCProfileUtils.vibrate(this);
    }
  }
 private Profile getPreviouslySelectedProfile() {
   Profile previous = null;
   SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
   String uuid = prefs.getString(PREFS_PREVIOUS_PROFILE, null);
   if (uuid != null) {
     previous = mProfileManager.getProfile(UUID.fromString(uuid));
   }
   return previous;
 }
  private void handleProfileMimeType(byte[] payload) {
    UUID profileUuid = NFCProfileUtils.toUUID(payload);
    Profile currentProfile = mProfileManager.getActiveProfile();

    if (currentProfile == null || !currentProfile.getUuid().equals(profileUuid)) {
      saveCurrentProfile();
      switchTo(profileUuid);
    } else if (currentProfile.getUuid().equals(profileUuid)) {
      Profile lastProfile = getPreviouslySelectedProfile();
      if (lastProfile != null) {
        switchTo(lastProfile.getUuid());
        clearPreviouslySelectedProfile();
      }
    }
  }
 private void saveCurrentProfile() {
   Profile currentProfile = mProfileManager.getActiveProfile();
   SharedPreferences.Editor editor = getSharedPreferences(PREFS_NAME, 0).edit();
   editor.putString(PREFS_PREVIOUS_PROFILE, currentProfile.getUuid().toString());
   editor.commit();
 }