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:de.sourcestream.movieDB.controller.MovieList.java

/**
 * Called to ask the fragment to save its current dynamic state,
 * so it can later be reconstructed in a new instance of its process is restarted.
 *
 * @param outState Bundle in which to place your saved state.
 *///from   w ww .  j a va  2  s. com
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // Used to avoid bug where we add item in the back stack
    // and if we change orientation twice the item from the back stack has null values
    if (save != null)
        outState.putBundle("save", save);
    else {
        Bundle send = new Bundle();
        send.putInt("checkLoadMore", checkLoadMore);
        send.putInt("totalPages", totalPages);
        send.putString("currentListURL", getCurrentList());
        send.putString("title", getTitle());
        send.putBoolean("isLoading", isLoading);
        send.putInt("lastVisitedMovie", lastVisitedMovie);
        if (backState == 1) {
            send.putInt("backState", 1);
            send.putParcelableArrayList("listData", moviesList);
            // used to restore the scroll listener variables
            send.putInt("currentPage", endlessScrollListener.getCurrentPage());
            send.putInt("oldCount", endlessScrollListener.getOldCount());
            send.putBoolean("loading", endlessScrollListener.getLoading());
            // Save scroll position
            if (listView != null) {
                Parcelable listState = listView.onSaveInstanceState();
                send.putParcelable("listViewScroll", listState);
            }
        } else
            send.putInt("backState", 0);

        outState.putBundle("save", send);
    }
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

private static void putNestedJSONObject(JSONObject jsonObject, Bundle bundle) throws JSONException {
    JSONArray names = jsonObject.names();
    for (int i = 0; i < names.length(); i++) {
        String name = names.getString(i);
        Object data = jsonObject.get(name);
        if (data == null) {
            continue;
        }//from ww  w.  ja  v a 2 s  .c om
        if (data instanceof Integer) {
            bundle.putInt(name, ((Integer) data).intValue());
        }
        if (data instanceof Float) {
            bundle.putFloat(name, ((Float) data).floatValue());
        }
        if (data instanceof Double) {
            bundle.putDouble(name, ((Double) data).doubleValue());
        }
        if (data instanceof Long) {
            bundle.putLong(name, ((Long) data).longValue());
        }
        if (data instanceof String) {
            bundle.putString(name, (String) data);
        }
        if (data instanceof Boolean) {
            bundle.putBoolean(name, ((Boolean) data).booleanValue());
        }
        // Nested JSONObject
        if (data instanceof JSONObject) {
            Bundle nestedBundle = new Bundle();
            bundle.putBundle(name, nestedBundle);
            putNestedJSONObject((JSONObject) data, nestedBundle);
        }
        // Nested JSONArray. Doesn't support mixed types in single array
        if (data instanceof JSONArray) {
            // Empty array. No way to tell what type of data to pass on, so skipping
            if (((JSONArray) data).length() == 0) {
                Log.e("Empty array not supported in nested JSONObject, skipping");
                continue;
            }
            // Integer
            if (((JSONArray) data).get(0) instanceof Integer) {
                int[] integerArrayData = new int[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    integerArrayData[j] = ((JSONArray) data).getInt(j);
                }
                bundle.putIntArray(name, integerArrayData);
            }
            // Double
            if (((JSONArray) data).get(0) instanceof Double) {
                double[] doubleArrayData = new double[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    doubleArrayData[j] = ((JSONArray) data).getDouble(j);
                }
                bundle.putDoubleArray(name, doubleArrayData);
            }
            // Long
            if (((JSONArray) data).get(0) instanceof Long) {
                long[] longArrayData = new long[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    longArrayData[j] = ((JSONArray) data).getLong(j);
                }
                bundle.putLongArray(name, longArrayData);
            }
            // String
            if (((JSONArray) data).get(0) instanceof String) {
                String[] stringArrayData = new String[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    stringArrayData[j] = ((JSONArray) data).getString(j);
                }
                bundle.putStringArray(name, stringArrayData);
            }
            // Boolean
            if (((JSONArray) data).get(0) instanceof Boolean) {
                boolean[] booleanArrayData = new boolean[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    booleanArrayData[j] = ((JSONArray) data).getBoolean(j);
                }
                bundle.putBooleanArray(name, booleanArrayData);
            }
        }
    }
}

From source file:org.alfresco.mobile.android.application.activity.MainActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBundle(MainActivityHelper.TAG,
            MainActivityHelper.createBundle(outState, currentAccount, capture, fragmentQueue, importParent));
}

From source file:org.opensilk.music.library.provider.LibraryProvider.java

private void writeCause(Bundle ok, LibraryException cause) {
    //HAX since the bundle is returned (i guess)
    //the system classloader remarshals the bundle before we
    //can set our classloader...causing ClassNotFoundException.
    //To remedy nest the cause in another bundle.
    Bundle b = new Bundle();
    b.putParcelable(Extras.CAUSE, cause);
    ok.putBundle(Extras.CAUSE, b);
}

From source file:androidx.media.MediaSession2StubImplBase.java

void notifyError(final int errorCode, final Bundle extras) {
    notifyAll(new Session2Runnable() {
        @Override/* w  w w  .  j a  v  a  2  s .c om*/
        public void run(ControllerInfo controller) throws RemoteException {
            Bundle bundle = new Bundle();
            bundle.putInt(ARGUMENT_ERROR_CODE, errorCode);
            bundle.putBundle(ARGUMENT_EXTRAS, extras);
            controller.getControllerBinder().onEvent(SESSION_EVENT_ON_ERROR, bundle);
        }
    });
}

From source file:com.waz.zclient.pages.main.conversation.LocationFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    // Dirty hack to avoid crash in MapView
    // See https://code.google.com/p/gmaps-api-issues/issues/detail?id=6237#c9
    final Bundle mapViewSaveState = new Bundle(outState);
    mapView.onSaveInstanceState(mapViewSaveState);
    outState.putBundle(MAP_VIEW_SAVE_STATE, mapViewSaveState);

    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
}

From source file:androidx.media.MediaSession2StubImplBase.java

private void connect(Bundle extras, final ResultReceiver cb) {
    final ControllerInfo controllerInfo = createControllerInfo(extras);
    mSession.getCallbackExecutor().execute(new Runnable() {
        @Override/*from  ww w .  j a  v  a 2  s .  c om*/
        public void run() {
            if (mSession.isClosed()) {
                return;
            }
            synchronized (mLock) {
                // Keep connecting controllers.
                // This helps sessions to call APIs in the onConnect()
                // (e.g. setCustomLayout()) instead of pending them.
                mConnectingControllers.add(controllerInfo.getId());
            }
            SessionCommandGroup2 allowedCommands = mSession.getCallback().onConnect(mSession.getInstance(),
                    controllerInfo);
            // Don't reject connection for the request from trusted app.
            // Otherwise server will fail to retrieve session's information to dispatch
            // media keys to.
            boolean accept = allowedCommands != null || controllerInfo.isTrusted();
            if (accept) {
                if (DEBUG) {
                    Log.d(TAG, "Accepting connection, controllerInfo=" + controllerInfo + " allowedCommands="
                            + allowedCommands);
                }
                if (allowedCommands == null) {
                    // For trusted apps, send non-null allowed commands to keep
                    // connection.
                    allowedCommands = new SessionCommandGroup2();
                }
                synchronized (mLock) {
                    mConnectingControllers.remove(controllerInfo.getId());
                    mControllers.put(controllerInfo.getId(), controllerInfo);
                    mAllowedCommandGroupMap.put(controllerInfo, allowedCommands);
                }
                // If connection is accepted, notify the current state to the
                // controller. It's needed because we cannot call synchronous calls
                // between session/controller.
                // Note: We're doing this after the onConnectionChanged(), but there's
                //       no guarantee that events here are notified after the
                //       onConnected() because IMediaController2 is oneway (i.e. async
                //       call) and Stub will use thread poll for incoming calls.
                final Bundle resultData = new Bundle();
                resultData.putBundle(ARGUMENT_ALLOWED_COMMANDS, allowedCommands.toBundle());
                resultData.putInt(ARGUMENT_PLAYER_STATE, mSession.getPlayerState());
                resultData.putInt(ARGUMENT_BUFFERING_STATE, mSession.getBufferingState());
                resultData.putParcelable(ARGUMENT_PLAYBACK_STATE_COMPAT, mSession.getPlaybackStateCompat());
                resultData.putInt(ARGUMENT_REPEAT_MODE, mSession.getRepeatMode());
                resultData.putInt(ARGUMENT_SHUFFLE_MODE, mSession.getShuffleMode());
                final List<MediaItem2> playlist = allowedCommands.hasCommand(COMMAND_CODE_PLAYLIST_GET_LIST)
                        ? mSession.getPlaylist()
                        : null;
                if (playlist != null) {
                    resultData.putParcelableArray(ARGUMENT_PLAYLIST,
                            MediaUtils2.toMediaItem2ParcelableArray(playlist));
                }
                final MediaItem2 currentMediaItem = allowedCommands.hasCommand(
                        COMMAND_CODE_PLAYLIST_GET_CURRENT_MEDIA_ITEM) ? mSession.getCurrentMediaItem() : null;
                if (currentMediaItem != null) {
                    resultData.putBundle(ARGUMENT_MEDIA_ITEM, currentMediaItem.toBundle());
                }
                resultData.putBundle(ARGUMENT_PLAYBACK_INFO, mSession.getPlaybackInfo().toBundle());
                final MediaMetadata2 playlistMetadata = mSession.getPlaylistMetadata();
                if (playlistMetadata != null) {
                    resultData.putBundle(ARGUMENT_PLAYLIST_METADATA, playlistMetadata.toBundle());
                }
                // Double check if session is still there, because close() can be
                // called in another thread.
                if (mSession.isClosed()) {
                    return;
                }
                cb.send(CONNECT_RESULT_CONNECTED, resultData);
            } else {
                synchronized (mLock) {
                    mConnectingControllers.remove(controllerInfo.getId());
                }
                if (DEBUG) {
                    Log.d(TAG, "Rejecting connection, controllerInfo=" + controllerInfo);
                }
                cb.send(CONNECT_RESULT_DISCONNECTED, null);
            }
        }
    });
}

From source file:bolts.AppLinkTest.java

public void testSimpleIntentWithAppLink() throws Exception {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    Bundle appLinkData = new Bundle();
    appLinkData.putString("target_url", "http://www.example2.com");
    appLinkData.putInt("version", 1);
    Bundle extras = new Bundle();
    extras.putString("foo", "bar");
    appLinkData.putBundle("extras", extras);
    i.putExtra("al_applink_data", appLinkData);

    assertEquals(Uri.parse("http://www.example2.com"), AppLinks.getTargetUrl(i));
    assertNotNull(AppLinks.getAppLinkData(i));
    assertNotNull(AppLinks.getAppLinkExtras(i));
    assertEquals("bar", AppLinks.getAppLinkExtras(i).getString("foo"));
}

From source file:de.sourcestream.movieDB.controller.SearchList.java

/**
 * Called to ask the fragment to save its current dynamic state,
 * so it can later be reconstructed in a new instance of its process is restarted.
 *
 * @param outState Bundle in which to place your saved state.
 *///www .j av a2 s  .  com
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // Used to avoid bug where we add item in the back stack
    // and if we change orientation twice the item from the back stack has null values
    if (save != null)
        outState.putBundle("save", save);
    else {
        Bundle send = new Bundle();
        send.putInt("totalPages", totalPages);
        send.putString("title", getTitle());
        if (backState == 1) {
            send.putInt("backState", 1);
            send.putParcelableArrayList("listData", searchList);
            // used to restore the scroll listener variables
            send.putInt("currentPage", endlessScrollListener.getCurrentPage());
            send.putInt("oldCount", endlessScrollListener.getOldCount());
            send.putBoolean("loading", endlessScrollListener.getLoading());
            // Save scroll position
            if (listView != null) {
                Parcelable listState = listView.onSaveInstanceState();
                send.putParcelable("listViewScroll", listState);
            }
        } else {
            send.putInt("backState", 0);
            send.putString("query", query);
        }
        outState.putBundle("save", send);
    }
}

From source file:android.support.design.internal.NavigationMenuPresenter.java

@Override
public Parcelable onSaveInstanceState() {
    if (Build.VERSION.SDK_INT >= 11) {
        // API 9-10 does not support ClassLoaderCreator, therefore things can crash if they're
        // loaded via different loaders. Rather than crash we just won't save state on those
        // platforms
        final Bundle state = new Bundle();
        if (mMenuView != null) {
            SparseArray<Parcelable> hierarchy = new SparseArray<>();
            mMenuView.saveHierarchyState(hierarchy);
            state.putSparseParcelableArray(STATE_HIERARCHY, hierarchy);
        }/* w w w.  j  a  v  a2 s . com*/
        if (mAdapter != null) {
            state.putBundle(STATE_ADAPTER, mAdapter.createInstanceState());
        }
        if (mHeaderLayout != null) {
            SparseArray<Parcelable> header = new SparseArray<>();
            mHeaderLayout.saveHierarchyState(header);
            state.putSparseParcelableArray(STATE_HEADER, header);
        }
        return state;
    }
    return null;
}