/** Creates an activity record from a text line created by toString() */
    public static ActivityRecord parseActivityRecord(String textLine) {

      ActivityRecord result = null;
      String[] fields = null;

      if (textLine != null) {
        try {
          // Splits the string
          fields = textLine.split(FIELDS_REGEXP);

          // Parses fixed lenght part
          if (fields.length > 3) {
            result = new ActivityRecord();

            // Parses the date
            result.date =
                !fields[0].equals(NULL_STRING) ? new Date(Long.parseLong(fields[0])) : null;

            // Parses the state
            result.state = !fields[1].equals(NULL_STRING) ? State.valueOf(fields[1]) : null;

            // Parses the action
            result.action = !fields[2].equals(NULL_STRING) ? StateAction.valueOf(fields[2]) : null;

            // Parses the requested action
            result.requestedAction =
                !fields[3].equals(NULL_STRING) ? RequestedAction.valueOf(fields[3]) : null;
          }

          // Parses variable length part
          if (fields.length > 4) {
            result.payload = new Object[fields.length - 4];
            System.arraycopy(fields, 4, result.payload, 0, fields.length - 4);
            parsePayload(result.payload);
          }

        } catch (Exception e) {
          Log.e(LOGTAG, "Error parsing activity record: " + textLine);
          Log.e(LOGTAG, Log.getStackTraceString(e));
          result = null;
        }
      }

      return result;
    }