android.os.Bundle.getParcelableArray()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中android.os.Bundle.getParcelableArray()方法的一些代码示例,展示了Bundle.getParcelableArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.getParcelableArray()方法的具体详情如下:
包路径:android.os.Bundle
类名称:Bundle
方法名:getParcelableArray

Bundle.getParcelableArray介绍

暂无

代码示例

代码示例来源:origin: seven332/EhViewer

private void handleArgs(Bundle args) {
  if (args == null) {
    return;
  }
  mApiUid = args.getLong(KEY_API_UID, -1L);
  mApiKey = args.getString(KEY_API_KEY);
  mGid = args.getLong(KEY_GID, -1L);
  mToken = args.getString(KEY_TOKEN, null);
  Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS);
  if (parcelables instanceof GalleryComment[]) {
    mComments = (GalleryComment[]) parcelables;
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

mPendingRequest = savedInstanceState.getInt(KEY_INSTANCE_STATE_PENDING_REQUEST);
mExistingAccounts =
    savedInstanceState.getParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS);

代码示例来源:origin: konmik/nucleus

when(bundle.getParcelableArray(anyString())).thenAnswer(get);

代码示例来源:origin: seven332/EhViewer

private void onRestore(@NonNull Bundle savedInstanceState) {
  mApiUid = savedInstanceState.getLong(KEY_API_UID, -1L);
  mApiKey = savedInstanceState.getString(KEY_API_KEY);
  mGid = savedInstanceState.getLong(KEY_GID, -1L);
  mToken = savedInstanceState.getString(KEY_TOKEN, null);
  Parcelable[] parcelables = savedInstanceState.getParcelableArray(KEY_COMMENTS);
  if (parcelables instanceof GalleryComment[]) {
    mComments = (GalleryComment[]) parcelables;
  }
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: androidannotations/androidannotations

Parcelable[] value = bundle.getParcelableArray(key);
if (value == null) {
  return null;

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  softwareComponents = (SoftwareComponent[]) getArguments().getParcelableArray(ARG_COMPONENTS);
  // Sort components by name
  Arrays.sort(softwareComponents, new Comparator<SoftwareComponent>() {
    @Override
    public int compare(SoftwareComponent o1, SoftwareComponent o2) {
      return o1.getName().compareTo(o2.getName());
    }
  });
}

代码示例来源:origin: rockerhieu/emojicon

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
  if (state != null) {
    Bundle bundle = (Bundle) state;
    Parcelable[] states = bundle.getParcelableArray("states");
    savedStates = new EmojiconGridView.SavedState[states.length];
    for (int i = 0; i < states.length; i++) {
      savedStates[i] = (EmojiconGridView.SavedState) states[i];
    }
  }
  super.restoreState(state, loader);
}

代码示例来源:origin: Cleveroad/SlidingTutorial-Android

/**
   * Returns the value associated with the given key, or null if no mapping of the desired type
   * exists for the given key or a null value is explicitly associated with the key.
   *
   * @param bundle     {@link Bundle} instance
   * @param key        key in bundle
   * @param classType  type of element in array
   * @param classArray type of elements array
   * @return array or null
   */
  @Nullable
  @SuppressWarnings("unchecked")
  static <T extends Parcelable> T[] getParcelableArray(@NonNull Bundle bundle, @NonNull String key, Class<T> classType, Class<T[]> classArray) {
    Parcelable[] parcelableArray = bundle.getParcelableArray(key);
    if (classArray.isInstance(parcelableArray)) {
      return (T[]) parcelableArray;
    } else if (parcelableArray != null) {
      int size = parcelableArray.length;
      T[] items = (T[]) Array.newInstance(classType, size);
      int index = 0;
      for (Parcelable parcelable : parcelableArray) {
        if (classType.isInstance(parcelable)) {
          items[index++] = (T) parcelable;
        }
      }
      return items;
    }
    return null;
  }
}

代码示例来源:origin: AppIntro/AppIntro

@Override
  public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
      Bundle bundle = (Bundle) state;
      bundle.setClassLoader(loader);
      Parcelable[] fss = bundle.getParcelableArray("states");
      mSavedState.clear();
      mFragments.clear();
      if (fss != null) {
        for (int i = 0; i < fss.length; i++) {
          mSavedState.add((Fragment.SavedState) fss[i]);
        }
      }
      Iterable<String> keys = bundle.keySet();
      for (String key : keys) {
        if (key.startsWith("f")) {
          int index = Integer.parseInt(key.substring(1));
          Fragment f = mFragmentManager.getFragment(bundle, key);
          if (f != null) {
            while (mFragments.size() <= index) {
              mFragments.add(null);
            }
            f.setMenuVisibility(false);
            mFragments.set(index, f);
          }
        }
      }
    }
  }
}

代码示例来源:origin: rockerhieu/emojicon

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
  GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView);
  Bundle bundle = getArguments();
  if (bundle == null) {
    mEmojiconType = Emojicon.TYPE_UNDEFINED;
    mEmojicons = People.DATA;
    mUseSystemDefault = false;
  } else {
    //noinspection WrongConstant
    mEmojiconType = bundle.getInt(ARG_EMOJICON_TYPE);
    if (mEmojiconType == Emojicon.TYPE_UNDEFINED) {
      Parcelable[] parcels = bundle.getParcelableArray(ARG_EMOJICONS);
      mEmojicons = new Emojicon[parcels.length];
      for (int i = 0; i < parcels.length; i++) {
        mEmojicons[i] = (Emojicon) parcels[i];
      }
    } else {
      mEmojicons = Emojicon.getEmojicons(mEmojiconType);
    }
    mUseSystemDefault = bundle.getBoolean(ARG_USE_SYSTEM_DEFAULTS);
  }
  gridView.setAdapter(new EmojiconAdapter(view.getContext(), mEmojicons, mUseSystemDefault));
  gridView.setOnItemClickListener(this);
}

代码示例来源:origin: google/cameraview

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  final Bundle args = getArguments();
  final AspectRatio[] ratios = (AspectRatio[]) args.getParcelableArray(ARG_ASPECT_RATIOS);
  if (ratios == null) {
    throw new RuntimeException("No ratios");
  }
  Arrays.sort(ratios);
  final AspectRatio current = args.getParcelable(ARG_CURRENT_ASPECT_RATIO);
  final AspectRatioAdapter adapter = new AspectRatioAdapter(ratios, current);
  return new AlertDialog.Builder(getActivity())
      .setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int position) {
          mListener.onAspectRatioSelected(ratios[position]);
        }
      })
      .create();
}

代码示例来源:origin: aa112901/remusic

Bundle bundle = (Bundle)state;
bundle.setClassLoader(loader);
Parcelable[] fss = bundle.getParcelableArray("states");
mSavedState.clear();
mFragments.clear();

代码示例来源:origin: seven332/EhViewer

@Override
protected void onSceneResult(int requestCode, int resultCode, Bundle data) {
  switch (requestCode) {
    case REQUEST_CODE_COMMENT_GALLERY:
      if (resultCode != RESULT_OK || data == null){
        break;
      }
      Parcelable[] array = data.getParcelableArray(GalleryCommentsScene.KEY_COMMENTS);
      if (!(array instanceof GalleryComment[])) {
        break;
      }
      GalleryComment[] comments = (GalleryComment[]) array;
      if (mGalleryDetail == null) {
        break;
      }
      mGalleryDetail.comments = comments;
      bindComments(comments);
      break;
    default:
      super.onSceneResult(requestCode, resultCode, data);
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
 public void parcelableArray() {
  Bundle innerBundle = new Bundle();
  innerBundle.putInt("value", 1);
  Parcelable[] arr = new Parcelable[] { innerBundle };
  bundle.putParcelableArray("foo", arr);

  assertThat(bundle.getParcelableArray("foo")).isEqualTo(arr);
  assertThat(bundle.getParcelableArray("bar")).isNull();
 }
}

代码示例来源:origin: stackoverflow.com

Bundle bundle = getIntent().getExtras();
Parcelable[] parcels = bundle.getParcelableArray(INTENT_EXTRA_ADDRESSES);

Address[] addresses = new Address[parcels.length];
for (Parcelable par : parcels){
   addresses.add((Address) par);              
}

代码示例来源:origin: firebase/firebase-jobdispatcher-android

@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]);
}

代码示例来源:origin: jberkel/sms-backup-plus

@Override @NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
  final Account[] accounts = (Account[]) getArguments().getParcelableArray(ACCOUNTS);
  final int[] checkedItem = {0};
  final ColorStateList colorStateList = ContextCompat.getColorStateList(getContext(), R.color.secondary_text);
  return new AlertDialog.Builder(getContext())
    .setTitle(R.string.select_google_account)
    .setIcon(getTinted(getResources(), R.drawable.ic_account_circle, colorStateList.getDefaultColor()))
    .setSingleChoiceItems(getNames(accounts), checkedItem[0], new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
        checkedItem[0] = which;
      }
    })
    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int which) {
        ((AccountManagerAuthActivity)getActivity()).onAccountSelected(accounts[checkedItem[0]]);
      }
    })
    .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
        ((AccountManagerAuthActivity)getActivity()).onCanceled();
      }
    })
    .create();
}

代码示例来源:origin: fengdai/FragmentMaster

/**
 * Retrieve extended data from the request.
 *
 * @param name The name of the desired item.
 * @return the value of an item that previously added with putExtra() or
 * null if no Parcelable[] value was found.
 * @see #putExtra(String, Parcelable[])
 */
public Parcelable[] getParcelableArrayExtra(String name) {
  return mExtras == null ? null : mExtras.getParcelableArray(name);
}

代码示例来源:origin: stackoverflow.com

@Override
public Bundle call(String method, String args, Bundle extras) {
  if (method.equals("customInsert")) {
    ContentValues[] values = extras.getParcelableArray("contentValues")
    // do bulk insert and return list of ids in a new Bundle
  }
}

相关文章

Bundle类方法