Example usage for android.os Bundle putBundle

List of usage examples for android.os Bundle putBundle

Introduction

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

Prototype

public void putBundle(@Nullable String key, @Nullable Bundle value) 

Source Link

Document

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

Usage

From source file:com.facebook.internal.BundleJSONConverterTest.java

@Test
public void testSimpleValues() throws JSONException {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1st");
    arrayList.add("2nd");
    arrayList.add("third");

    Bundle innerBundle1 = new Bundle();
    innerBundle1.putInt("inner", 1);

    Bundle innerBundle2 = new Bundle();
    innerBundle2.putString("inner", "2");
    innerBundle2.putStringArray("deep list", new String[] { "7", "8" });

    innerBundle1.putBundle("nested bundle", innerBundle2);

    Bundle b = new Bundle();
    b.putBoolean("boolValue", true);
    b.putInt("intValue", 7);
    b.putLong("longValue", 5000000000l);
    b.putDouble("doubleValue", 3.14);
    b.putString("stringValue", "hello world");
    b.putStringArray("stringArrayValue", new String[] { "first", "second" });
    b.putStringArrayList("stringArrayListValue", arrayList);
    b.putBundle("nested", innerBundle1);

    JSONObject json = BundleJSONConverter.convertToJSON(b);
    assertNotNull(json);//from   w  w  w.  ja va2s .c  o m

    assertEquals(true, json.getBoolean("boolValue"));
    assertEquals(7, json.getInt("intValue"));
    assertEquals(5000000000l, json.getLong("longValue"));
    assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", json.getString("stringValue"));

    JSONArray jsonArray = json.getJSONArray("stringArrayValue");
    assertEquals(2, jsonArray.length());
    assertEquals("first", jsonArray.getString(0));
    assertEquals("second", jsonArray.getString(1));

    jsonArray = json.getJSONArray("stringArrayListValue");
    assertEquals(3, jsonArray.length());
    assertEquals("1st", jsonArray.getString(0));
    assertEquals("2nd", jsonArray.getString(1));
    assertEquals("third", jsonArray.getString(2));

    JSONObject innerJson = json.getJSONObject("nested");
    assertEquals(1, innerJson.getInt("inner"));
    innerJson = innerJson.getJSONObject("nested bundle");
    assertEquals("2", innerJson.getString("inner"));

    jsonArray = innerJson.getJSONArray("deep list");
    assertEquals(2, jsonArray.length());
    assertEquals("7", jsonArray.getString(0));
    assertEquals("8", jsonArray.getString(1));

    Bundle finalBundle = BundleJSONConverter.convertToBundle(json);
    assertNotNull(finalBundle);

    assertEquals(true, finalBundle.getBoolean("boolValue"));
    assertEquals(7, finalBundle.getInt("intValue"));
    assertEquals(5000000000l, finalBundle.getLong("longValue"));
    assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", finalBundle.getString("stringValue"));

    List<String> stringList = finalBundle.getStringArrayList("stringArrayValue");
    assertEquals(2, stringList.size());
    assertEquals("first", stringList.get(0));
    assertEquals("second", stringList.get(1));

    stringList = finalBundle.getStringArrayList("stringArrayListValue");
    assertEquals(3, stringList.size());
    assertEquals("1st", stringList.get(0));
    assertEquals("2nd", stringList.get(1));
    assertEquals("third", stringList.get(2));

    Bundle finalInnerBundle = finalBundle.getBundle("nested");
    assertEquals(1, finalInnerBundle.getInt("inner"));
    finalBundle = finalInnerBundle.getBundle("nested bundle");
    assertEquals("2", finalBundle.getString("inner"));

    stringList = finalBundle.getStringArrayList("deep list");
    assertEquals(2, stringList.size());
    assertEquals("7", stringList.get(0));
    assertEquals("8", stringList.get(1));
}

From source file:org.apache.cordova.mediacapture.PendingRequests.java

/**
 * Save the current pending requests to a bundle for saving when the Activity gets destroyed.
 *
 * @return  A Bundle that can be used to restore state using setLastSavedState()
 */// w  ww  .j  a  v a2 s.  com
public synchronized Bundle toBundle() {
    Bundle bundle = new Bundle();
    bundle.putInt(CURRENT_ID_KEY, currentReqId);

    for (int i = 0; i < requests.size(); i++) {
        Request r = requests.valueAt(i);
        int requestCode = requests.keyAt(i);
        bundle.putBundle(REQUEST_KEY_PREFIX + requestCode, r.toBundle());
    }

    if (requests.size() > 1) {
        // This scenario is hopefully very unlikely because there isn't much that can be
        // done about it. Should only occur if an external Activity is launched while
        // there is a pending permission request and the device is on low memory
        LOG.w(LOG_TAG,
                "More than one media capture request pending on Activity destruction. Some requests will be dropped!");
    }

    return bundle;
}

From source file:com.frostwire.android.gui.fragments.ImageViewerFragment.java

private Bundle prepareFileBundle(FileDescriptor fd, int offset, boolean inFullScreenMode) {
    Bundle result = new Bundle();
    result.putBundle(EXTRA_FILE_DESCRIPTOR_BUNDLE, fd.toBundle());
    result.putBoolean(EXTRA_IN_FULL_SCREEN_MODE, inFullScreenMode);
    result.putInt(EXTRA_ADAPTER_FILE_OFFSET, offset);
    return result;
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java

public void loadContent(boolean onlyFnsMsg, Bundle cramConfig) {
    mCurrentFragment = StudyOptionsFragment.newInstance(0, false, null);
    Bundle args = getIntent().getExtras();
    if (onlyFnsMsg) {
        args.putBoolean("onlyFnsMsg", onlyFnsMsg);
    }/*from www .  j  a v a  2  s.co m*/
    if (cramConfig != null) {
        args.putBundle("cramInitialConfig", cramConfig);
    }
    mCurrentFragment.setArguments(args);
    getSupportFragmentManager().beginTransaction().add(android.R.id.content, mCurrentFragment).commit();
}

From source file:dev.dworks.libs.awizard.WizardActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBundle("model", mWizardModel.save());
    outState.putBoolean("dataChanged", mDataChanged);
}

From source file:com.battlelancer.seriesguide.ui.SearchActivity.java

private void submitSearchQuery(String query) {
    Bundle args = new Bundle();
    args.putString(SearchManager.QUERY, query);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        Bundle appData = extras.getBundle(SearchManager.APP_DATA);
        if (appData != null) {
            args.putBundle(SearchManager.APP_DATA, appData);
        }// w  w w.j  a v  a 2  s.c om
    }

    submitSearchQuery(args);
}

From source file:com.google.samples.apps.iosched.map.MapActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    // Save the mapview state in a separate bundle parameter
    final Bundle mapviewState = new Bundle();
    mMapFragment.onSaveInstanceState(mapviewState);
    outState.putBundle(BUNDLE_STATE_MAPVIEW, mapviewState);
}

From source file:org.apache.cordova.X5CordovaInterfaceImpl.java

/**
 * Saves parameters for startActivityForResult().
 *//* w  ww. j  a  v  a2s .c  om*/
public void onSaveInstanceState(Bundle outState) {
    if (activityResultCallback != null) {
        String serviceName = activityResultCallback.getServiceName();
        outState.putString("callbackService", serviceName);
    }
    if (pluginManager != null) {
        outState.putBundle("plugin", pluginManager.onSaveInstanceState());
    }

}

From source file:com.todoroo.astrid.activity.TaskListFragment.java

/**
 * Instantiates and returns an instance of TaskListFragment (or some subclass). Custom types of
 * TaskListFragment can be created, with the following precedence:
 *
 * --If the filter is of type {@link FilterWithCustomIntent}, the task list type it specifies will be used
 * --Otherwise, the specified customComponent will be used
 *
 * See also: instantiateWithFilterAndExtras(Filter, Bundle) which uses TaskListFragment as the default
 * custom component./*from   ww  w.  j  a va  2  s .  c  o  m*/
 * @param filter
 * @param extras
 * @param customComponent
 * @return
 */
@SuppressWarnings("nls")
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras,
        Class<?> customComponent) {
    Class<?> component = customComponent;
    if (filter instanceof FilterWithCustomIntent && component == null) {
        try {
            component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName());
        } catch (Exception e) {
            // Invalid
        }
    }
    if (component == null)
        component = TaskListFragment.class;

    TaskListFragment newFragment;
    try {
        newFragment = (TaskListFragment) component.newInstance();
    } catch (java.lang.InstantiationException e) {
        Log.e("tla-instantiate", "tla-instantiate", e);
        newFragment = new TaskListFragment();
    } catch (IllegalAccessException e) {
        Log.e("tla-instantiate", "tla-instantiate", e);
        newFragment = new TaskListFragment();
    }
    Bundle args = new Bundle();
    args.putBundle(TOKEN_EXTRAS, extras);
    newFragment.setArguments(args);
    return newFragment;
}

From source file:com.btmura.android.reddit.app.CommentListController.java

@Override
public void saveInstanceState(Bundle outState) {
    outState.putInt(EXTRA_FILTER, filter);
    outState.putBundle(EXTRA_CURSOR_EXTRAS, cursorExtras);
}