Bundle extras = getIntent().getExtras(); int[] arrayInB = extras.getIntArray("my_array");
/** * Gets an array of int values out of the object. * @param key The key for the value. * @return The int values. */ @Nullable public int[] getIntArray(final String key) { return this.bundle.getIntArray(key); }
private void onRestore(Bundle savedInstanceState) { mUrlBuilder = savedInstanceState.getParcelable(KEY_URL_BUILDER); if (mUrlBuilder == null) { mUrlBuilder = new FavListUrlBuilder(); } mSearchMode = savedInstanceState.getBoolean(KEY_SEARCH_MODE); mHasFirstRefresh = savedInstanceState.getBoolean(KEY_HAS_FIRST_REFRESH); mFavCountArray = savedInstanceState.getIntArray(KEY_FAV_COUNT_ARRAY); }
@Override public void restoreState(Parcelable state, ClassLoader loader) { Bundle bundle = (Bundle)state; if (state != null) { savesState = bundle.getBoolean(KEY_SAVES_STATE, false); savedPages = bundle.getSparseParcelableArray(KEY_SAVED_PAGES); int[] visiblePageIdsKeys = bundle.getIntArray(KEY_VISIBLE_PAGE_IDS_KEYS); String[] visiblePageIdsValues = bundle.getStringArray(KEY_VISIBLE_PAGE_IDS_VALUES); visiblePageIds = new SparseArray<>(visiblePageIdsKeys.length); for (int i = 0; i < visiblePageIdsKeys.length; i++) { visiblePageIds.put(visiblePageIdsKeys[i], visiblePageIdsValues[i]); } } }
@Override public void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; mDataChanged = true; mSyncHeight = bundle.getInt("height"); long firstId = bundle.getLong("firstId"); if (firstId >= 0) { mNeedSync = true; SavedState ss = new SavedState(); ss.firstId = firstId; ss.height = (int) mSyncHeight; ss.position = bundle.getInt("position"); ss.viewTop = bundle.getInt("viewTop"); ss.childCount = bundle.getInt("childCount"); ss.viewTops = bundle.getIntArray("viewTops"); mPendingSync = ss; mSyncRowId = ss.firstId; mSyncPosition = ss.position; mSpecificTop = ss.viewTop; mSpecificTops = ss.viewTops; } state = bundle.getParcelable("instanceState"); } super.onRestoreInstanceState(state); requestLayout(); } }//end of class
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mTitleResId = getArguments().getInt(KEY_TITLE_ID); mColumns = getArguments().getInt(KEY_COLUMNS); mSize = getArguments().getInt(KEY_SIZE); } if (savedInstanceState != null) { mColors = savedInstanceState.getIntArray(KEY_COLORS); mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR); } }
@Test public void intArray() { int [] arr = new int[] { 87, 65 }; bundle.putIntArray("foo", arr); assertThat(bundle.getIntArray("foo")).isEqualTo(arr); assertThat(bundle.getIntArray("bar")).isNull(); }
@Override protected void onReceiveResult(int resultCode, Bundle resultData) { super.onReceiveResult(resultCode, resultData); int[] grantResult = resultData.getIntArray("grantResult"); String[] permissions = resultData.getStringArray("permissions"); // Call the callback with the result callback.onComplete(new PermissionResponse(permissions, grantResult, resultCode)); } };
when(bundle.getIntArray(anyString())).thenAnswer(get);
int[] allowedGestures = bundle.getIntArray(UCrop.Options.EXTRA_ALLOWED_GESTURES); if (allowedGestures != null && allowedGestures.length == TABS_COUNT) { mAllowedGestures = allowedGestures;
@Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.preferences_category); Preference category = findPreference(getString(R.string.pref_category)); int summary, title; if ((title = getArguments().getInt(EXTRA_TITLE, 0)) != 0) { category.setTitle(title); } if ((summary = getArguments().getInt(EXTRA_SUMMARY, 0)) != 0) { category.setSummary(summary); } int[] preferences = getArguments().getIntArray(EXTRA_XML_PREFERENCES); if (preferences != null) { for (int preference : preferences) { addPreferencesFromResource(preference); } } } }
@Test public void getWrongType() { bundle.putFloat("foo", 5f); assertThat(bundle.getCharArray("foo")).isNull(); assertThat(bundle.getInt("foo")).isEqualTo(0); assertThat(bundle.getIntArray("foo")).isNull(); assertThat(bundle.getIntegerArrayList("foo")).isNull(); assertThat(bundle.getShort("foo")).isEqualTo((short) 0); assertThat(bundle.getShortArray("foo")).isNull(); assertThat(bundle.getBoolean("foo")).isFalse(); assertThat(bundle.getBooleanArray("foo")).isNull(); assertThat(bundle.getLong("foo")).isEqualTo(0); assertThat(bundle.getLongArray("foo")).isNull(); assertThat(bundle.getFloatArray("foo")).isNull(); assertThat(bundle.getDouble("foo")).isEqualTo(0.0); assertThat(bundle.getDoubleArray("foo")).isNull(); assertThat(bundle.getString("foo")).isNull(); assertThat(bundle.getStringArray("foo")).isNull(); assertThat(bundle.getStringArrayList("foo")).isNull(); assertThat(bundle.getBundle("foo")).isNull(); assertThat((Parcelable) bundle.getParcelable("foo")).isNull(); assertThat(bundle.getParcelableArray("foo")).isNull(); assertThat(bundle.getParcelableArrayList("foo")).isNull(); bundle.putInt("foo", 1); assertThat(bundle.getFloat("foo")).isEqualTo(0.0f); }
@Test public void testWriteToBundle_contentUriTrigger() { ObservedUri observedUri = new ObservedUri(ContactsContract.AUTHORITY_URI, Flags.FLAG_NOTIFY_FOR_DESCENDANTS); ContentUriTrigger contentUriTrigger = Trigger.contentUriTrigger(Arrays.asList(observedUri)); Bundle bundle = writer.writeToBundle( initializeDefaultBuilder().setTrigger(contentUriTrigger).build(), new Bundle()); Uri[] uris = (Uri[]) bundle.getParcelableArray(BundleProtocol.PACKED_PARAM_CONTENT_URI_ARRAY); int[] flags = bundle.getIntArray(BundleProtocol.PACKED_PARAM_CONTENT_URI_FLAGS_ARRAY); assertTrue("Array size", uris.length == flags.length && flags.length == 1); assertEquals( BundleProtocol.PACKED_PARAM_CONTENT_URI_ARRAY, ContactsContract.AUTHORITY_URI, uris[0]); assertEquals( BundleProtocol.PACKED_PARAM_CONTENT_URI_FLAGS_ARRAY, Flags.FLAG_NOTIFY_FOR_DESCENDANTS, flags[0]); }
protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); final int[] position = savedInstanceState.getIntArray("ARTICLE_SCROLL_POSITION"); if(position != null) mScrollView.post(new Runnable() { public void run() { mScrollView.scrollTo(position[0], position[1]); } }); }
assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY), cachedBundle.getShortArray(SHORT_ARRAY_KEY)); assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY)); assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY)); assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY)); assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
int selectedTabIndex = savedInstanceState.getInt(SELECTED_TAB_INDEX_EXTRA); selectedTab = selectedTabIndex != -1 ? tabs.get(selectedTabIndex) : null; padding = savedInstanceState.getIntArray(PADDING_EXTRA); applyPaddingToTabs = savedInstanceState.getBoolean(APPLY_PADDING_TO_TABS_EXTRA); tabIconId = savedInstanceState.getInt(TAB_ICON_ID_EXTRA);
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mTitleResId = getArguments().getInt(KEY_TITLE_ID); mColumns = getArguments().getInt(KEY_COLUMNS); mSize = getArguments().getInt(KEY_SIZE); } if (savedInstanceState != null) { mColors = savedInstanceState.getIntArray(KEY_COLORS); mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR); mColorContentDescriptions = savedInstanceState.getStringArray( KEY_COLOR_CONTENT_DESCRIPTIONS); } }
public class ImageSwitch1 extends Activity{ public void onCreate...(redacted) Bundle b=this.getIntent().getExtras(); int[] mThumb = b.getIntArray("mThumbSent"); }
@Override public void onViewStateRestored(@Nullable Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); if (savedInstanceState != null) { scrollPosition = savedInstanceState.getIntArray(TAG_SCROLL_POSITION); if (scrollPosition != null && scrollPosition.length == 2) pieceMapScrollView.scrollTo(scrollPosition[0], scrollPosition[1]); } }
private BufferCallbackTimes(Parcel source) { Bundle in = source.readBundle(getClass().getClassLoader()); mTimeStamps = in.getIntArray("mTimeStamps"); mCallbackDurations = in.getShortArray("mCallbackDurations"); mExpectedBufferPeriod = in.getShort("mExpectedBufferPeriod"); mExceededCapacity = in.getBoolean("mExceededCapacity"); mIndex = in.getInt("mIndex"); }