@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    if (created) {
      // Prevent overwriting attributes that are already set
      return;
    } else {
      created = true;
    }

    if (getArguments() != null) {
      ip = getArguments().getString(ARG_IP);
      type = TcpConnectionManager.ReceiverType.valueOf(getArguments().getString(ARG_TYPE));
      menu = getArguments().getInt(ARG_MENU);
    } else {
      Log.e(LOG_TAG, "onCreate: getArguments()==null");
      ip = "";
      type = TcpConnectionManager.ReceiverType.UNSPECIFIED;
      menu = 0;
    }

    tcpConnectionManager = TcpConnectionManager.getInstance(getActivity().getApplicationContext());

    connection = tcpConnectionManager.requireConnection(this);
  }
 public static SpinnerFragment newInstance(
     String ip, TcpConnectionManager.ReceiverType type, int menu) {
   SpinnerFragment fragment = new SpinnerFragment();
   Bundle args = new Bundle();
   args.putString(ARG_IP, ip);
   args.putString(ARG_TYPE, type.toString());
   args.putInt(ARG_MENU, menu);
   fragment.setArguments(args);
   return fragment;
 }
 public static SpinnerFragment recoverFromRecreationKey(String key) {
   try {
     String[] args = Util.split(key, SEP, 0);
     String ip = args[2];
     TcpConnectionManager.ReceiverType type = TcpConnectionManager.ReceiverType.valueOf(args[3]);
     int menu = Integer.parseInt(args[4]);
     SpinnerFragment fragment = newInstance(ip, type, menu);
     fragment.recoverPos(args[1]);
     return fragment;
   } catch (Exception e) {
     Log.e(LOG_TAG, "recoverFromRecreationKey: illegal key: " + key);
     Log.e(LOG_TAG, "Got exception: " + e);
     return null;
   }
 }