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:net.reichholf.dreamdroid.activities.ServiceListActivity.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable("history", mHistory);
    outState.putBoolean("isBouquetList", mIsBouquetList);

}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java

public void getCars(final Location location) {
    final String url = API.carsNearby + "/" + location.getLatitude() + "/" + location.getLongitude();

    try {// ww w .j a  va2s.c  o  m
        final API.doRequest task = new API.doRequest(new API.doRequest.TaskListener() {
            @Override
            public void postExecute(JSONArray result) throws JSONException {
                JSONObject serverResponse = result.getJSONObject(result.length() - 1);
                int statusCode = serverResponse.getInt("statusCode");

                result.remove(result.length() - 1);

                final FragmentActivity activity = getActivity();
                if (activity == null) {
                    return;
                }
                final ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
                if (statusCode == 200) {
                    final View view = getView();
                    if (view == null) {
                        return;
                    }
                    final ListView listView = (ListView) view.findViewById(R.id.listView);

                    final ArrayList<CarData> carsArray = new ArrayList<CarData>();

                    for (int i = 0; i < result.length(); i++) {
                        final CarData tempCarData = new CarData(result.getJSONObject(i));
                        carsArray.add(tempCarData);

                        final LatLng carLocation = new LatLng(tempCarData.lat, tempCarData.lng);
                        mMap.addMarker(new MarkerOptions().position(carLocation).title(tempCarData.title)
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.models)));
                    }

                    Collections.sort(carsArray, new Comparator<CarData>() {
                        @Override
                        public int compare(CarData lhs, CarData rhs) {
                            return lhs.distance - rhs.distance;
                        }
                    });

                    final CarDataAdapter adapter = new CarDataAdapter(activity.getApplicationContext(),
                            carsArray);
                    listView.setAdapter(adapter);

                    final ArrayList<CarData> finalCarsArray = carsArray;

                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
                            final Intent carDetails = new Intent(view.getContext(), CarDetails.class);

                            final Bundle bundle = new Bundle();
                            bundle.putSerializable("carData", finalCarsArray.get(position));
                            carDetails.putExtras(bundle);

                            startActivity(carDetails);
                        }
                    });

                    if (carsArray.size() == 0) {
                        final Toast toast = Toast.makeText(activity.getApplicationContext(),
                                "No car available in this area. Location information may be incorrect. Make sure GPS or Wifi is effective and try again. Or, Free Plan limitation, ask administrator to delete registered cars.",
                                Toast.LENGTH_LONG);
                        toast.show();
                        supportActionBar.setTitle("No car available.");
                    } else {
                        final String title = (carsArray.size() == 1) ? "1 car found."
                                : carsArray.size() + " cars found.";
                        supportActionBar.setTitle(title);
                    }

                    Log.i("Car Data", result.toString());
                } else if (statusCode == 500) {
                    final Toast toast = Toast.makeText(activity.getApplicationContext(),
                            "A server internal error received. Ask your administrator.", Toast.LENGTH_LONG);
                    toast.show();
                    supportActionBar.setTitle("Error: Server internal error.");
                } else {
                    final Toast toast = Toast.makeText(activity.getApplicationContext(),
                            "Error: Unable to connect to server.", Toast.LENGTH_LONG);
                    toast.show();
                    supportActionBar.setTitle("Error: Not connected to server.");
                }
            }
        });

        task.execute(url, "GET").get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

From source file:com.example.jonas.materialmockups.activities.ExhibitDetailsActivity.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putSerializable(KEY_EXHIBIT_PAGES, (Serializable) exhibitPages);
    outState.putInt(KEY_CURRENT_PAGE_INDEX, currentPageIndex);
    outState.putBoolean(KEY_AUDIO_PLAYING, isAudioPlaying);
    outState.putBoolean(KEY_AUDIO_TOOLBAR_HIDDEN, isAudioToolbarHidden);
    outState.putBundle(KEY_EXTRAS, extras);
}

From source file:com.example.skode6.scanenvy.MainActivity.java

public void onSaveInstanceState(Bundle savedState) {

    super.onSaveInstanceState(savedState);

    // Note: getValues() is a method in your ArrayAdaptor subclass
    List<Product> values = adapter.getValues();
    for (int i = 0; i < values.size(); i++) {
        savedState.putSerializable("product" + i, values.get(i));
    }/* www .  j a  va  2  s  .  c  om*/
}

From source file:com.edicon.firebase.devs.firepix.GeoFireFragment.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    // Save currently selected layout manager.
    // ToDo: getRecyclerViewScrollPosition();
    int recyclerViewScrollPosition = 0;
    Log.d(TAG, "Recycler view scroll position: " + recyclerViewScrollPosition);
    savedInstanceState.putSerializable(KEY_LAYOUT_POSITION, recyclerViewScrollPosition);

    savedInstanceState.putParcelable(MyLocation.LOCATION_KEY, MyLocation.currentLocation);
    savedInstanceState.putString(MyLocation.LAST_UPDATED_TIME_STRING_KEY, MyLocation.lastUpdateTime);

    super.onSaveInstanceState(savedInstanceState);
}

From source file:com.optimusinfo.elasticpath.cortex.profile.address.AddressActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putSerializable(KEY_GEOGRAPHIES, mGeographies);
    outState.putSerializable(KEY_REGIONS, mRegions);
    if (mObjAddress != null) {
        outState.putSerializable(Constants.PageUrl.INTENT_ADRESS, mObjAddress);

    }/*from   www.j av a2s  .  co m*/
    outState.putInt(KEY_POSITION_COUNTRIES, mSPCountry.getSelectedItemPosition());
    outState.putInt(KEY_POSITION_REGIONS, mSPProvince.getSelectedItemPosition());
    outState.putString(KEY_ADDRESS_POST, mAddressPostUrl);

}

From source file:at.jclehner.rxdroid.NotificationReceiver.java

private void scheduleNextBeginOrEndAlarm(DoseTimeInfo dtInfo, boolean scheduleEnd) {
    final int doseTime = scheduleEnd ? dtInfo.activeDoseTime() : dtInfo.nextDoseTime();
    final Calendar time = dtInfo.currentTime();
    final Date doseTimeDate = scheduleEnd ? dtInfo.activeDate() : dtInfo.nextDoseTimeDate();

    final Bundle alarmExtras = new Bundle();
    alarmExtras.putSerializable(EXTRA_DATE, doseTimeDate);
    alarmExtras.putInt(EXTRA_DOSE_TIME, doseTime);
    alarmExtras.putBoolean(EXTRA_IS_DOSE_TIME_END, scheduleEnd);
    alarmExtras.putBoolean(EXTRA_SILENT, false);

    long offset;//from   w  w  w  . j a va2s. c o m

    if (scheduleEnd)
        offset = Settings.getMillisUntilDoseTimeEnd(time, doseTime);
    else
        offset = Settings.getMillisUntilDoseTimeBegin(time, doseTime);

    long triggerAtMillis = time.getTimeInMillis() + offset;

    final long alarmRepeatMins = Settings.getStringAsInt(Settings.Keys.ALARM_REPEAT, 0);
    final long alarmRepeatMillis = alarmRepeatMins == -1 ? 10000 : alarmRepeatMins * 60000;

    if (alarmRepeatMillis > 0) {
        alarmExtras.putBoolean(EXTRA_FORCE_UPDATE, true);

        final long base = dtInfo.activeDate().getTime();
        int i = 0;

        while (base + (i * alarmRepeatMillis) < time.getTimeInMillis())
            ++i;

        // We must tell the receiver whether the alarm is an actual dose time's
        // end or begin, or merely a repetition.

        final long triggerAtMillisWithRepeatedAlarm = base + i * alarmRepeatMillis;
        if (triggerAtMillisWithRepeatedAlarm < triggerAtMillis) {
            triggerAtMillis = triggerAtMillisWithRepeatedAlarm;
            alarmExtras.putBoolean(EXTRA_IS_ALARM_REPETITION, true);
        }

        //triggerAtMillis = base + (i * alarmRepeatMillis);
    }

    final long triggerDiffFromNow = triggerAtMillis - System.currentTimeMillis();
    if (triggerDiffFromNow < 0) {
        if (triggerDiffFromNow < -50000)
            Log.w(TAG, "Alarm time is in the past by less than 5 seconds.");
        else {
            Log.w(TAG, "Alarm time is in the past. Ignoring...");
            return;
        }
    }

    if (alarmExtras.getBoolean(EXTRA_IS_ALARM_REPETITION))
        Log.i(TAG, "Scheduling next alarm for " + DateTime.toString(triggerAtMillis));
    else {
        Log.i(TAG, "Scheduling " + (scheduleEnd ? "end" : "begin") + " of doseTime " + doseTime + " on date "
                + DateTime.toDateString(doseTimeDate) + " for " + DateTime.toString(triggerAtMillis));
    }

    Log.i(TAG, "Alarm will go off in " + Util.millis(triggerDiffFromNow));

    mAlarmMgr.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, createOperation(alarmExtras));
}

From source file:edu.mit.mobile.android.locast.net.NetworkClient.java

public static Bundle jsonObjectToBundle(JSONObject jsonObject, boolean allStrings) {
    final Bundle b = new Bundle();
    for (@SuppressWarnings("unchecked")
    final Iterator<String> i = jsonObject.keys(); i.hasNext();) {
        final String key = i.next();
        final Object value = jsonObject.opt(key);
        if (value == null) {
            b.putSerializable(key, null);

        } else if (allStrings) {
            b.putString(key, String.valueOf(value));

        } else if (value instanceof String) {
            b.putString(key, (String) value);

        } else if (value instanceof Integer) {
            b.putInt(key, (Integer) value);
        }/*w ww  .j a  va  2  s  . c o  m*/
    }
    return b;
}

From source file:name.gumartinm.weather.information.fragment.overview.OverviewFragment.java

@Override
public void onSaveInstanceState(final Bundle savedInstanceState) {

    // Save UI state
    final PermanentStorage store = new PermanentStorage(this.getActivity().getApplicationContext());
    final Forecast forecast = store.getForecast();

    if (forecast != null) {
        savedInstanceState.putSerializable("Forecast", forecast);
    }//  ww w  . j  ava2s.c o m

    super.onSaveInstanceState(savedInstanceState);
}

From source file:com.mycelium.wallet.activity.send.SendMainActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putSerializable("amountToSend", _amountToSend);
    savedInstanceState.putSerializable("receivingAddress", _receivingAddress);
    savedInstanceState.putString("transactionLabel", _transactionLabel);
}