Example usage for android.os Bundle putSerializable

List of usage examples for android.os Bundle putSerializable

Introduction

In this page you can find the example usage for android.os Bundle putSerializable.

Prototype

@Override
public void putSerializable(@Nullable String key, @Nullable Serializable value) 

Source Link

Document

Inserts a Serializable value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

private void loadSelectBuildingActivity(GeoPoint loc, boolean invisibleSelection) {

    Intent placeIntent = new Intent(UnifiedNavigationActivity.this, SelectBuildingActivity.class);
    Bundle b = new Bundle();

    if (loc != null) {
        b.putString("coordinates_lat", String.valueOf(loc.dlat));
        b.putString("coordinates_lon", String.valueOf(loc.dlon));
    }//ww  w .j  a  v a 2  s  .c  o m
    b.putSerializable("mode",
            invisibleSelection ? SelectBuildingActivity.Mode.INVISIBLE : SelectBuildingActivity.Mode.NONE);
    placeIntent.putExtras(b);

    // start the activity where the user can select the building he is in
    startActivityForResult(placeIntent, SELECT_PLACE_ACTIVITY_RESULT);
}

From source file:com.leavjenn.smoothdaterangepicker.date.SmoothDateRangePickerFragment.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_SELECTED_YEAR, mCalendar.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH, mCalendar.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY, mCalendar.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_SELECTED_YEAR_END, mCalendarEnd.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH_END, mCalendarEnd.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY_END, mCalendarEnd.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_YEAR_START, mMinYear);
    outState.putInt(KEY_YEAR_END, mMaxYear);

    outState.putInt(KEY_WEEK_START, mWeekStart);
    outState.putInt(KEY_CURRENT_VIEW, mCurrentView);
    int listPosition = -1;
    int listPositionEnd = -1;
    if (mCurrentView == MONTH_AND_DAY_VIEW) {
        listPosition = mDayPickerView.getMostVisiblePosition();
    } else if (mCurrentView == YEAR_VIEW) {
        listPosition = mYearPickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mYearPickerView.getFirstPositionOffset());
    } else if (mCurrentView == MONTH_AND_DAY_VIEW_END) {
        listPositionEnd = mDayPickerViewEnd.getMostVisiblePosition();
    } else if (mCurrentView == YEAR_VIEW_END) {
        listPositionEnd = mYearPickerViewEnd.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET_END, mYearPickerViewEnd.getFirstPositionOffset());
    }//w w  w . j  a v a  2  s .co  m
    outState.putInt(KEY_LIST_POSITION, listPosition);
    outState.putInt(KEY_LIST_POSITION_END, listPositionEnd);
    outState.putSerializable(KEY_MIN_DATE, mMinDate);
    outState.putSerializable(KEY_MAX_DATE, mMaxDate);
    outState.putSerializable(KEY_MIN_DATE_SELECTABLE, mMinSelectableDate);
    outState.putSerializable(KEY_HIGHLIGHTED_DAYS, highlightedDays);
    outState.putSerializable(KEY_SELECTABLE_DAYS, selectableDays);
    outState.putBoolean(KEY_THEME_DARK, mThemeDark);
    outState.putInt(KEY_ACCENT, mAccentColor);
    outState.putBoolean(KEY_VIBRATE, mVibrate);
    outState.putBoolean(KEY_DISMISS, mDismissOnPause);
}

From source file:com.borax12.materialdaterangepicker.date.DatePickerDialog.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_SELECTED_YEAR, mCalendar.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH, mCalendar.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY, mCalendar.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_WEEK_START, mWeekStart);
    outState.putInt(KEY_YEAR_START, mMinYear);
    outState.putInt(KEY_MAX_YEAR, mMaxYear);
    outState.putInt(KEY_CURRENT_VIEW, mCurrentView);
    outState.putInt(KEY_SELECTED_YEAR_END, mCalendarEnd.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH_END, mCalendarEnd.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY_END, mCalendarEnd.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_WEEK_START_END, mWeekStartEnd);
    outState.putInt(KEY_YEAR_START_END, mMinYear);
    outState.putInt(KEY_MAX_YEAR_END, mMaxYear);
    outState.putInt(KEY_CURRENT_VIEW_END, mCurrentViewEnd);
    int listPosition = -1;
    int listPositionEnd = -1;
    if (mCurrentView == MONTH_AND_DAY_VIEW || mCurrentViewEnd == MONTH_AND_DAY_VIEW) {
        listPosition = mDayPickerView.getMostVisiblePosition();
        listPositionEnd = mDayPickerViewEnd.getMostVisiblePosition();

    } else if (mCurrentView == YEAR_VIEW || mCurrentViewEnd == YEAR_VIEW) {
        listPosition = mYearPickerView.getFirstVisiblePosition();
        listPositionEnd = mYearPickerViewEnd.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mYearPickerView.getFirstPositionOffset());
        outState.putInt(KEY_LIST_POSITION_OFFSET_END, mYearPickerViewEnd.getFirstPositionOffset());
    }/*w ww .  ja v a 2 s  . c  om*/
    outState.putInt(KEY_LIST_POSITION, listPosition);
    outState.putInt(KEY_LIST_POSITION_END, listPositionEnd);
    outState.putSerializable(KEY_MIN_DATE, mMinDate);
    outState.putSerializable(KEY_MAX_DATE, mMaxDate);
    outState.putSerializable(KEY_MIN_DATE_END, mMinDateEnd);
    outState.putSerializable(KEY_MAX_DATE_END, mMaxDateEnd);
    outState.putSerializable(KEY_HIGHLIGHTED_DAYS, highlightedDays);
    outState.putSerializable(KEY_SELECTABLE_DAYS, selectableDays);
    outState.putSerializable(KEY_HIGHLIGHTED_DAYS_END, highlightedDaysEnd);
    outState.putSerializable(KEY_SELECTABLE_DAYS_END, selectableDaysEnd);
    outState.putBoolean(KEY_THEME_DARK, mThemeDark);
    outState.putInt(KEY_ACCENT, mAccentColor);
    outState.putBoolean(KEY_VIBRATE, mVibrate);
    outState.putBoolean(KEY_DISMISS, mDismissOnPause);
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    if (mColorFilter != null) {
        savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilterColor);
    }/*from  ww w . j av  a 2 s.com*/
    savedInstanceState.putBoolean(KEY_IS_SUGGESTION_LIST_COLLAPSED, mIsSuggestionListCollapsed);
    savedInstanceState.putLong(KEY_PREVIOUS_CONTACT_ID, mPreviousContactId);
    savedInstanceState.putBoolean(KEY_SUGGESTIONS_AUTO_SELECTED, mSuggestionsShouldAutoSelected);
    savedInstanceState.putSerializable(KEY_SELECTED_SUGGESTION_CONTACTS, mSelectedAggregationIds);
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

/**
 * ??// w w  w  .j  a v  a  2s  . c om
 *
 * @param outState Bundle
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    Field[] fields = this.getClass().getDeclaredFields();
    Field.setAccessible(fields, true);
    Annotation[] ans;
    for (Field f : fields) {
        ans = f.getDeclaredAnnotations();
        for (Annotation an : ans) {
            if (an instanceof SaveWithActivity) {
                try {
                    Object o = f.get(this);
                    if (o == null) {
                        continue;
                    }
                    String fieldName = f.getName();
                    if (o instanceof Integer) {
                        outState.putInt(fieldName, f.getInt(this));
                    } else if (o instanceof String) {
                        outState.putString(fieldName, (String) f.get(this));
                    } else if (o instanceof Long) {
                        outState.putLong(fieldName, f.getLong(this));
                    } else if (o instanceof Short) {
                        outState.putShort(fieldName, f.getShort(this));
                    } else if (o instanceof Boolean) {
                        outState.putBoolean(fieldName, f.getBoolean(this));
                    } else if (o instanceof Byte) {
                        outState.putByte(fieldName, f.getByte(this));
                    } else if (o instanceof Character) {
                        outState.putChar(fieldName, f.getChar(this));
                    } else if (o instanceof CharSequence) {
                        outState.putCharSequence(fieldName, (CharSequence) f.get(this));
                    } else if (o instanceof Float) {
                        outState.putFloat(fieldName, f.getFloat(this));
                    } else if (o instanceof Double) {
                        outState.putDouble(fieldName, f.getDouble(this));
                    } else if (o instanceof String[]) {
                        outState.putStringArray(fieldName, (String[]) f.get(this));
                    } else if (o instanceof Parcelable) {
                        outState.putParcelable(fieldName, (Parcelable) f.get(this));
                    } else if (o instanceof Serializable) {
                        outState.putSerializable(fieldName, (Serializable) f.get(this));
                    } else if (o instanceof Bundle) {
                        outState.putBundle(fieldName, (Bundle) f.get(this));
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    super.onSaveInstanceState(outState);
}

From source file:com.customdatepicker.time.TimePickerDialog.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    if (mTimePicker != null) {
        outState.putParcelable(KEY_INITIAL_TIME, mTimePicker.getTime());
        outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
        outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
        outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
        if (mInKbMode) {
            outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
        }//from  ww  w.  ja v a 2s . co  m
        outState.putString(KEY_TITLE, mTitle);
        outState.putBoolean(KEY_THEME_DARK, mThemeDark);
        outState.putBoolean(KEY_THEME_DARK_CHANGED, mThemeDarkChanged);
        outState.putInt(KEY_ACCENT, mAccentColor);
        outState.putBoolean(KEY_VIBRATE, mVibrate);
        outState.putBoolean(KEY_DISMISS, mDismissOnPause);
        outState.putParcelableArray(KEY_SELECTABLE_TIMES, mSelectableTimes);
        outState.putParcelable(KEY_MIN_TIME, mMinTime);
        outState.putParcelable(KEY_MAX_TIME, mMaxTime);
        outState.putBoolean(KEY_ENABLE_SECONDS, mEnableSeconds);
        outState.putBoolean(KEY_ENABLE_MINUTES, mEnableMinutes);
        outState.putInt(KEY_OK_RESID, mOkResid);
        outState.putString(KEY_OK_STRING, mOkString);
        outState.putInt(KEY_OK_COLOR, mOkColor);
        outState.putInt(KEY_CANCEL_RESID, mCancelResid);
        outState.putString(KEY_CANCEL_STRING, mCancelString);
        outState.putInt(KEY_CANCEL_COLOR, mCancelColor);
        outState.putSerializable(KEY_VERSION, mVersion);
    }
}

From source file:com.kenmeidearu.materialdatetimepicker.date.DatePickerDialog.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_SELECTED_YEAR, mCalendar.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH, mCalendar.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY, mCalendar.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_SELECTABLE_HOUR, mCalendar.get(Calendar.HOUR_OF_DAY));
    outState.putInt(KEY_WEEK_START, mWeekStart);
    outState.putInt(KEY_YEAR_START, mMinYear);
    outState.putInt(KEY_YEAR_END, mMaxYear);
    outState.putInt(KEY_CURRENT_VIEW, mCurrentView);
    int listPosition = -1;
    if (mCurrentView == MONTH_AND_DAY_VIEW) {
        listPosition = mDayPickerView.getMostVisiblePosition();
    } else if (mCurrentView == MONTH_VIEW) {
        listPosition = mMonthPickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mMonthPickerView.getFirstPositionOffset());
    } else if (mCurrentView == YEAR_VIEW) {
        listPosition = mYearPickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mYearPickerView.getFirstPositionOffset());
    } else if (mCurrentView == HOUR_INDEX) {
        listPosition = mHourPickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mHourPickerView.getFirstPositionOffset());
    } else if (mCurrentView == MINUTE_INDEX) {
        listPosition = mMinutePickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mMinutePickerView.getFirstPositionOffset());
    } else if (mCurrentView == SECOND_INDEX) {
        listPosition = mSecondPickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mSecondPickerView.getFirstPositionOffset());
    }//  w ww . j  a va 2s  . com
    outState.putInt(KEY_LIST_POSITION, listPosition);
    outState.putSerializable(KEY_MIN_DATE, mMinDate);
    outState.putSerializable(KEY_MAX_DATE, mMaxDate);
    outState.putSerializable(KEY_HIGHLIGHTED_DAYS, highlightedDays);
    outState.putSerializable(KEY_SELECTABLE_DAYS, selectableDays);
    outState.putSerializable(KEY_DISABLED_DAYS, disabledDays);
    outState.putBoolean(KEY_THEME_DARK, mThemeDark);
    outState.putBoolean(KEY_THEME_DARK_CHANGED, mThemeDarkChanged);
    outState.putInt(KEY_ACCENT, mAccentColor);
    outState.putBoolean(KEY_VIBRATE, mVibrate);
    outState.putBoolean(KEY_DISMISS, mDismissOnPause);
    outState.putBoolean(KEY_AUTO_DISMISS, mAutoDismiss);
    outState.putInt(KEY_DEFAULT_VIEW, mDefaultView);
    outState.putString(KEY_TITLE, mTitle);
    outState.putInt(KEY_OK_RESID, mOkResid);
    outState.putString(KEY_OK_STRING, mOkString);
    outState.putInt(KEY_CANCEL_RESID, mCancelResid);
    outState.putString(KEY_CANCEL_STRING, mCancelString);
    //time
    outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
    outState.putParcelable(KEY_INITIAL_TIME, mInitialTime);
    outState.putBoolean(KEY_ENABLE_SECONDS, mEnableSeconds);
    outState.putBoolean(KEY_ENABLE_MINUTES, mEnableMinutes);

}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putInt(RUNTIME_STATE, mState.ordinal());

    if (mPendingAddInfo.container != ItemInfo.NO_ID && mWaitingForResult) {
        outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
        outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
    }/*from   w  ww .  j av a2  s .c om*/

    // Save the current AppsCustomize tab
    if (mAppsCustomizeTabHost != null) {
        AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
        String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
        if (currentTabTag != null) {
            outState.putString("apps_customize_currentTab", currentTabTag);
        }
        int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
        outState.putInt("apps_customize_currentIndex", currentIndex);
    }
    outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);

    super.onSaveInstanceState(outState);
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java

/**
 * Save the fragment state/* w  w w  . ja va  2  s . c  o m*/
 * @param outState state to save to
 */
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // get the possibly changed values from the currently active pager fragments before saving state
    getFragmentValuesByPosition(mCurrentTab);

    // save dagvergunning state
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_MARKT_ID, mMarktId);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_DAG, mDag);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_ID, mId);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE,
            mErkenningsnummer);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_METHODE,
            mErkenningsnummerInvoerMethode);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_DATUMTIJD, mRegistratieDatumtijd);
    outState.putDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LAT,
            mRegistratieGeolocatieLatitude);
    outState.putDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LONG,
            mRegistratieGeolocatieLongitude);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_TOTALE_LENGTE, mTotaleLengte);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_STATUS_SOLLICITATIE, mSollicitatieStatus);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_AANWEZIG, mKoopmanAanwezig);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_KOOPMAN_ID, mKoopmanId);
    outState.putString(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS, mKoopmanVoorletters);
    outState.putString(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM, mKoopmanAchternaam);
    outState.putString(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL, mKoopmanFoto);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_ACCOUNT_ID, mRegistratieAccountId);
    outState.putString(MakkelijkeMarktProvider.Account.COL_NAAM, mRegistratieAccountNaam);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_SOLLICITATIE_ID, mSollicitatieId);
    outState.putInt(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER, mSollicitatieNummer);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_NOTITIE, mNotitie);
    outState.putSerializable(STATE_BUNDLE_KEY_PRODUCTS, mProducten);
    outState.putSerializable(STATE_BUNDLE_KEY_PRODUCTS_VAST, mProductenVast);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ID, mVervangerId);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ERKENNINGSNUMMER,
            mVervangerErkenningsnummer);

    // save viewpager state
    outState.putInt(CURRENT_TAB, mCurrentTab);
    getChildFragmentManager().putFragment(outState, KOOPMAN_FRAGMENT_TAG, mKoopmanFragment);
    getChildFragmentManager().putFragment(outState, PRODUCT_FRAGMENT_TAG, mProductFragment);
    getChildFragmentManager().putFragment(outState, OVERZICHT_FRAGMENT_TAG, mOverzichtFragment);
}

From source file:com.antew.redditinpictures.library.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri action = intent.getData();/*w  w w.j a v a2 s .c o  m*/
    Bundle extras = intent.getExtras();

    if (extras == null || action == null) {
        Ln.e("You did not pass extras or data with the Intent.");
        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    RequestCode requestCode = (RequestCode) extras.getSerializable(EXTRA_REQUEST_CODE);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    String cookie = extras.getString(EXTRA_COOKIE);
    String userAgent = extras.getString(EXTRA_USER_AGENT);

    // Items in this bundle are simply passed on in onRequestComplete
    Bundle passThrough = extras.getBundle(EXTRA_PASS_THROUGH);

    HttpEntity responseEntity = null;
    Intent result = new Intent(Constants.Broadcast.BROADCAST_HTTP_FINISHED);
    result.putExtra(EXTRA_PASS_THROUGH, passThrough);
    Bundle resultData = new Bundle();

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case
            // below.
            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            DefaultHttpClient client = new DefaultHttpClient();

            // GZip requests
            // antew on 3/12/2014 - Disabling GZIP for now, need to figure this CloseGuard error:
            // 03-12 21:02:09.248    9674-9683/com.antew.redditinpictures.pro E/StrictMode A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
            //         java.lang.Throwable: Explicit termination method 'end' not called
            // at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            // at java.util.zip.Inflater.<init>(Inflater.java:82)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
            // at com.antew.redditinpictures.library.service.RESTService$GzipDecompressingEntity.getContent(RESTService.java:346)
            client.addRequestInterceptor(getGzipRequestInterceptor());
            client.addResponseInterceptor(getGzipResponseInterceptor());

            if (cookie != null) {
                request.addHeader("Cookie", cookie);
            }

            if (userAgent != null) {
                request.addHeader("User-Agent", Constants.Reddit.USER_AGENT);
            }

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Ln.d("Executing request: %s %s ", verbToString(verb), action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            if (responseEntity != null) {
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                resultData.putSerializable(EXTRA_REQUEST_CODE, requestCode);
                resultData.putInt(EXTRA_STATUS_CODE, statusCode);
                result.putExtra(EXTRA_BUNDLE, resultData);

                onRequestComplete(result);
            } else {
                onRequestFailed(result, statusCode);
            }
        }
    } catch (URISyntaxException e) {
        Ln.e(e, "URI syntax was incorrect. %s %s ", verbToString(verb), action.toString());
        onRequestFailed(result, 0);
    } catch (UnsupportedEncodingException e) {
        Ln.e(e, "A UrlEncodedFormEntity was created with an unsupported encoding.");
        onRequestFailed(result, 0);
    } catch (ClientProtocolException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } catch (IOException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } finally {
        if (responseEntity != null) {
            try {
                responseEntity.consumeContent();
            } catch (IOException ignored) {
            }
        }
    }
}